• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

Revisióne42c89377c28153e6f3b9fc8fd4ef1de4df9764a (tree)
Tiempo2016-09-29 21:43:07
AutorSteve Kondik <steve@cyng...>
CommiterSteve Kondik

Log Message

Merge branch 'bt.lnx.2.1.r5-rel' of git://codeaurora.org/platform/system/bt into cm-14.0

Change-Id: I149f61cfa37c4930d54f6451aaff4405936daa8b

Cambiar Resumen

Diferencia incremental

--- a/Android.mk
+++ b/Android.mk
@@ -11,7 +11,7 @@ endif
1111
1212 ifeq ($(TARGET_BUILD_VARIANT),userdebug)
1313 ifneq ($(BOARD_HAS_QCA_BT_ROME),true)
14-bdroid_CFLAGS += -DQLOGKIT_USERDEBUG
14+bluetooth_CFLAGS += -DQLOGKIT_USERDEBUG
1515 endif
1616 endif
1717
@@ -21,9 +21,10 @@ endif
2121
2222 ifeq ($(TARGET_BUILD_VARIANT),eng)
2323 bluetooth_CFLAGS += -DBLUEDROID_DEBUG
24-bluetooth_CFLAGS += -DUSE_AUDIO_TRACK
2524 endif
2625
26+bluetooth_CFLAGS += -DUSE_AUDIO_TRACK
27+
2728 bluetooth_CFLAGS += -DEXPORT_SYMBOL="__attribute__((visibility(\"default\")))"
2829
2930 #
--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -883,7 +883,7 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
883883 #ifdef BTA_AV_SPLIT_A2DP_ENABLED
884884 keyval = (char *)hash_map_get(params, "A2dpStarted");
885885
886- if (keyval >= 0)
886+ if (keyval != NULL)
887887 {
888888 INFO("out_set_parameters, param: A2dpStarted");
889889 if (strcmp(keyval, "true") == 0)
--- a/bta/ag/bta_ag_cmd.c
+++ b/bta/ag/bta_ag_cmd.c
@@ -1239,7 +1239,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
12391239 /* if the devices does not support HFP 1.7, report DUT's HFP version as 1.6 */
12401240 if (p_scb->peer_version < HFP_VERSION_1_7)
12411241 {
1242- /* For PTS keep flags as is */
1242+ /* For PTS keep flags as is. */
12431243 if (property_get("bt.pts.certification", value, "false") &&
12441244 strcmp(value, "true") != 0)
12451245 {
@@ -1247,11 +1247,11 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
12471247 }
12481248 }
12491249 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)))
12511251 {
12521252 APPL_TRACE_WARNING("%s: Remote is hfp 1.7 but does not support HF indicators" \
12531253 "unset hf indicator bit from BRSF", __func__);
1254- /* For PTS keep flags as is */
1254+ /* For PTS keep flags as is. */
12551255 if (property_get("bt.pts.certification", value, "false") &&
12561256 strcmp(value, "true") != 0)
12571257 {
--- a/bta/av/bta_av_aact.c
+++ b/bta/av/bta_av_aact.c
@@ -105,7 +105,9 @@ const tBTA_AV_CO_FUNCTS bta_av_a2d_cos =
105105 bta_av_co_audio_start,
106106 bta_av_co_audio_stop,
107107 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
109111 };
110112
111113 /* ssm action functions for audio stream */
--- a/bta/av/bta_av_api.c
+++ b/bta/av/bta_av_api.c
@@ -343,6 +343,26 @@ void BTA_AvEnableMultiCast(BOOLEAN state, tBTA_AV_HNDL handle)
343343
344344 /*******************************************************************************
345345 **
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+**
346366 ** Function BTA_AvReconfig
347367 **
348368 ** Description Reconfigure the audio/video stream.
--- a/bta/av/bta_av_int.h
+++ b/bta/av/bta_av_int.h
@@ -113,6 +113,7 @@ enum
113113 #endif
114114 BTA_AV_API_START_EVT, /* the following 2 events must be in the same order as the *AP_*EVT */
115115 BTA_AV_API_STOP_EVT,
116+ BTA_AV_UPDATE_MAX_AV_CLIENTS_EVT,
116117 BTA_AV_ENABLE_MULTICAST_EVT /* Event for enable and disable multicast */
117118 };
118119
@@ -186,6 +187,8 @@ typedef void (*tBTA_AV_CO_STOP) (tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type);
186187 typedef void * (*tBTA_AV_CO_DATAPATH) (tBTA_AV_CODEC codec_type,
187188 UINT32 *p_len, UINT32 *p_timestamp);
188189 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);
189192
190193 /* the call-out functions for one stream */
191194 typedef struct
@@ -200,6 +203,8 @@ typedef struct
200203 tBTA_AV_CO_STOP stop;
201204 tBTA_AV_CO_DATAPATH data;
202205 tBTA_AV_CO_DELAY delay;
206+ tBTA_AV_CO_OFFLOAD_SUPPORT offload;
207+ tBTA_AV_CO_OFFLOAD_CAP cap;
203208 } tBTA_AV_CO_FUNCTS;
204209
205210 /* data type for BTA_AV_API_ENABLE_EVT */
@@ -256,6 +261,13 @@ typedef struct
256261 BOOLEAN is_multicast_enabled;
257262 } tBTA_AV_ENABLE_MULTICAST;
258263
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+
259271 /* data type for BTA_AV_API_DISCONNECT_EVT */
260272 typedef struct
261273 {
@@ -450,6 +462,7 @@ typedef union
450462 tBTA_AV_API_META_RSP api_meta_rsp;
451463 tBTA_AV_API_STATUS_RSP api_status_rsp;
452464 tBTA_AV_ENABLE_MULTICAST multicast_state;
465+ tBTA_AV_MAX_CLIENT max_av_clients;
453466 } tBTA_AV_DATA;
454467
455468 typedef void (tBTA_AV_VDP_DATA_ACT)(void *p_scb);
--- a/bta/av/bta_av_main.c
+++ b/bta/av/bta_av_main.c
@@ -73,6 +73,14 @@
7373 #define BTA_AV_RS_TIME_VAL 1000
7474 #endif
7575
76+/* offload codecs support */
77+enum
78+{
79+ APTX = 1,
80+ AAC,
81+ APTX_HD
82+};
83+
7684 /* state machine states */
7785 enum
7886 {
@@ -179,6 +187,7 @@ static void bta_av_sco_chg_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8
179187 static void bta_av_sys_rs_cback (tBTA_SYS_CONN_STATUS status,UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
180188
181189 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);
182191
183192 /* action functions */
184193 const tBTA_AV_NSM_ACT bta_av_nsm_act[] =
@@ -202,6 +211,7 @@ const tBTA_AV_NSM_ACT bta_av_nsm_act[] =
202211 #endif
203212 bta_av_api_to_ssm, /* BTA_AV_API_START_EVT */
204213 bta_av_api_to_ssm, /* BTA_AV_API_STOP_EVT */
214+ bta_av_api_update_max_av_clients,
205215 bta_av_api_enable_multicast, /* BTA_AV_ENABLE_MULTICAST_EVT */
206216 };
207217
@@ -683,6 +693,43 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
683693 (*bta_av_a2d_cos.init)(&codec_type, cs.cfg.codec_info,
684694 &cs.cfg.num_protect, cs.cfg.protect_info, index) == TRUE)
685695 {
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+
686733 if(AVDT_CreateStream(&p_scb->seps[index - startIndex].av_handle, &cs) ==
687734 AVDT_SUCCESS)
688735 {
@@ -807,6 +854,9 @@ void bta_av_api_deregister(tBTA_AV_DATA *p_data)
807854 {
808855 tBTA_AV_SCB *p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific);
809856
857+ // de-initialize aptX
858+ A2D_deinit_aptX();
859+
810860 if(p_scb)
811861 {
812862 p_scb->deregistring = TRUE;
@@ -930,6 +980,22 @@ static void bta_av_api_enable_multicast(tBTA_AV_DATA *p_data)
930980
931981 /*******************************************************************************
932982 **
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+**
933999 ** Function bta_av_chk_start
9341000 **
9351001 ** Description if this is audio channel, check if more than one audio
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -490,6 +490,7 @@ static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status )
490490 void bta_dm_disable (tBTA_DM_MSG *p_data)
491491 {
492492 UNUSED(p_data);
493+ int soc_type = get_soc_type();
493494
494495 /* Set l2cap idle timeout to 0 (so BTE immediately disconnects ACL link after last channel is closed) */
495496 L2CA_SetIdleTimeoutByBdAddr((UINT8 *)BT_BD_ANY, 0, BT_TRANSPORT_BR_EDR);
@@ -509,11 +510,12 @@ void bta_dm_disable (tBTA_DM_MSG *p_data)
509510 BTM_BleClearBgConnDev();
510511 #endif
511512
512-#ifdef QLOGKIT_USERDEBUG
513513 /* 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+ }
517519
518520 if(BTM_GetNumAclLinks()==0)
519521 {
@@ -3315,9 +3317,12 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
33153317 {
33163318 if (bta_dm_cb.device_list.count < BTA_DM_NUM_PEER_DEVICE)
33173319 {
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]));
33183322 bdcpy(bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].peer_bdaddr, p_bda);
33193323 bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].link_policy = bta_dm_cb.cur_policy;
33203324 bta_dm_cb.device_list.count++;
3325+ APPL_TRACE_ERROR("%s new acl connetion:count = %d", __func__, bta_dm_cb.device_list.count);
33213326 #if BLE_INCLUDED == TRUE
33223327 bta_dm_cb.device_list.peer_device[i].conn_handle = p_data->acl_change.handle;
33233328 if (p_data->acl_change.transport == BT_TRANSPORT_LE)
@@ -3368,10 +3373,12 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
33683373
33693374 conn.link_down.is_removed = bta_dm_cb.device_list.peer_device[i].remove_dev_pending;
33703375
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++)
33723378 {
33733379 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]));
33743380 }
3381+ memset(&bta_dm_cb.device_list.peer_device[i], 0, sizeof(bta_dm_cb.device_list.peer_device[i]));
33753382 break;
33763383 }
33773384 if(bta_dm_cb.device_list.count)
--- a/bta/hl/bta_hl_act.c
+++ b/bta/hl/bta_hl_act.c
@@ -414,7 +414,7 @@ void bta_hl_dch_ci_get_tx_data(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx,
414414 tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
415415 tBTA_HL_MDL_CB *p_dcb = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
416416 tMCA_RESULT result;
417- tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
417+ tBTA_HL_STATUS status;
418418 BOOLEAN free_buf = FALSE;
419419 BOOLEAN close_dch = FALSE;
420420 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,
423423 #if (BTA_HL_DEBUG == TRUE)
424424 APPL_TRACE_DEBUG("bta_hl_dch_ci_get_tx_data");
425425 #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+ }
427431 p_dcb->cout_oper &= ~BTA_HL_CO_GET_TX_DATA_MASK;
428432
429433 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,
436440 close_dch = TRUE;
437441 }
438442 }
443+ else if (status == BTA_HL_STATUS_FAIL)
444+ {
445+ free_buf = TRUE;
446+ }
439447 else
440448 {
441449 if ((result = MCA_WriteReq((tMCA_DL) p_dcb->mdl_handle, p_dcb->p_tx_pkt)) != MCA_SUCCESS)
--- a/bta/include/bta_av_api.h
+++ b/bta/include/bta_av_api.h
@@ -704,6 +704,17 @@ void BTA_AvEnableMultiCast(BOOLEAN state, tBTA_AV_HNDL handle);
704704
705705 /*******************************************************************************
706706 **
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+**
707718 ** Function BTA_AvReconfig
708719 **
709720 ** Description Reconfigure the audio/video stream.
--- a/bta/include/bta_av_co.h
+++ b/bta/include/bta_av_co.h
@@ -401,4 +401,28 @@ extern void bta_av_co_audio_delay(tBTA_AV_HNDL hndl, UINT16 delay);
401401 *******************************************************************************/
402402 extern void bta_av_co_video_delay(tBTA_AV_HNDL hndl, UINT16 delay);
403403
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+
404428 #endif /* BTA_AV_CO_H */
--- a/bta/jv/bta_jv_act.c
+++ b/bta/jv/bta_jv_act.c
@@ -2185,25 +2185,25 @@ static void bta_jv_pm_conn_busy(tBTA_JV_PM_CB *p_cb)
21852185 {
21862186 if ((NULL != p_cb) && (BTA_JV_PM_IDLE_ST == p_cb->state))
21872187 {
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);
21982197 }
21992198 }
2199+
22002200 }
22012201
22022202 /*******************************************************************************
22032203 **
2204- ** Function bta_jv_pm_conn_busy
2204+ ** Function bta_jv_pm_conn_idle
22052205 **
2206- ** Description set pm connection busy state (input param safe)
2206+ ** Description set pm connection idle state (input param safe)
22072207 **
22082208 ** Params p_cb: pm control block of jv connection
22092209 **
@@ -2215,11 +2215,9 @@ static void bta_jv_pm_conn_idle(tBTA_JV_PM_CB *p_cb)
22152215 if ((NULL != p_cb) && (BTA_JV_PM_IDLE_ST != p_cb->state)) {
22162216 APPL_TRACE_DEBUG("bta_jv_pm_conn_idle, p_cb: %p", p_cb);
22172217 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);
22232221 }
22242222 }
22252223
@@ -2710,18 +2708,8 @@ extern void bta_jv_l2cap_close_fixed (tBTA_JV_MSG *p_data)
27102708 void bta_jv_idle_timeout_handler(void *tle) {
27112709 tBTA_JV_PM_CB *p_cb = (tBTA_JV_PM_CB *)tle;;
27122710 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+ {
27252713 bta_jv_pm_state_change(p_cb, BTA_JV_CONN_IDLE);
27262714 }
27272715 }
--- a/btif/co/bta_av_co.c
+++ b/btif/co/bta_av_co.c
@@ -236,6 +236,7 @@ extern BOOLEAN btif_av_is_codec_offload_supported(int codec);
236236 #else
237237 #define btif_av_is_codec_offload_supported(codec) (0)
238238 #endif
239+extern BOOLEAN btif_av_is_offload_supported();
239240 extern BOOLEAN bt_split_a2dp_enabled;
240241 /*******************************************************************************
241242 **
@@ -1996,7 +1997,15 @@ UINT8 bta_av_select_codec(UINT8 hdl)
19961997 APPL_TRACE_ERROR("%s hdl = %d",__func__,hdl);
19971998 /* Retrieve the peer info */
19981999 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+ }
20002009 return bta_av_co_cb.codec_cfg->id;
20012010 }
20022011 }
@@ -2281,3 +2290,33 @@ BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max)
22812290
22822291 return TRUE;
22832292 }
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+}
--- a/btif/co/bta_hh_co.c
+++ b/btif/co/bta_hh_co.c
@@ -250,8 +250,24 @@ static int uhid_read_event(btif_hh_device_t *p_dev)
250250 btif_hh_setreport(p_dev, BTHH_FEATURE_REPORT,
251251 ev.u.output.size, ev.u.output.data);
252252 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);
253268 btif_hh_setreport(p_dev, BTHH_OUTPUT_REPORT,
254269 ev.u.output.size, ev.u.output.data);
270+ }
255271 else
256272 btif_hh_setreport(p_dev, BTHH_INPUT_REPORT,
257273 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
512528
513529 p_dev->dev_status = BTHH_CONN_STATE_CONNECTED;
514530 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);
515532 p_dev->set_rpt_id_list = list_new(lst_free_cb);
516533 if (!p_dev->set_rpt_id_list) {
517534 APPL_TRACE_ERROR("%s: unable to create list", __func__);
@@ -555,6 +572,7 @@ void bta_hh_co_close(UINT8 dev_handle, UINT8 app_id)
555572 "dev_status = %d, dev_handle =%d"
556573 ,__func__,p_dev->dev_status
557574 ,p_dev->dev_handle);
575+ memset(&p_dev->last_output_rpt_data, 0, BTIF_HH_OUTPUT_REPORT_SIZE);
558576 btif_hh_close_poll_thread(p_dev);
559577 break;
560578 }
--- a/btif/co/bta_hl_co.c
+++ b/btif/co/bta_hl_co.c
@@ -332,7 +332,7 @@ void bta_hl_co_get_tx_data (UINT8 app_id, tBTA_HL_MDL_HANDLE mdl_handle,
332332 {
333333 p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
334334
335- if (p_dcb->tx_size <= buf_size )
335+ if ((p_dcb->tx_size <= buf_size) && p_dcb->p_tx_pkt)
336336 {
337337 memcpy(p_buf, p_dcb->p_tx_pkt, p_dcb->tx_size);
338338 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,
341341 }
342342 }
343343
344-
344+ BTIF_TRACE_WARNING("%s status = %d ", __FUNCTION__, status);
345345 bta_hl_ci_get_tx_data(mdl_handle, status, evt);
346346
347347 }
--- a/btif/include/btif_hh.h
+++ b/btif/include/btif_hh.h
@@ -38,7 +38,7 @@
3838 #define BTIF_HH_KEYSTATE_MASK_NUMLOCK 0x01
3939 #define BTIF_HH_KEYSTATE_MASK_CAPSLOCK 0x02
4040 #define BTIF_HH_KEYSTATE_MASK_SCROLLLOCK 0x04
41-
41+#define BTIF_HH_OUTPUT_REPORT_SIZE 2
4242
4343 /*******************************************************************************
4444 ** Type definitions and return values
@@ -71,6 +71,7 @@ typedef struct
7171 list_t *set_rpt_id_list; // Owns a collection of set_rpt_id objects.
7272 UINT8 get_rpt_snt;
7373 BOOLEAN local_vup; // Indicated locally initiated VUP
74+ UINT8 last_output_rpt_data[BTIF_HH_OUTPUT_REPORT_SIZE];
7475 } btif_hh_device_t;
7576
7677 /* Control block to maintain properties of devices */
--- a/btif/src/bluetooth.c
+++ b/btif/src/bluetooth.c
@@ -48,6 +48,7 @@
4848 #include "bt_utils.h"
4949 #include "btif_api.h"
5050 #include "btif_common.h"
51+#include "device/include/controller.h"
5152 #include "btif_debug.h"
5253 #include "btsnoop.h"
5354 #include "btsnoop_mem.h"
@@ -527,6 +528,8 @@ int config_hci_snoop_log(uint8_t enable)
527528 return BT_STATUS_NOT_READY;
528529
529530 btsnoop_get_interface()->set_api_wants_to_log(enable);
531+ controller_get_static_interface()->enable_soc_logging(enable);
532+
530533 return BT_STATUS_SUCCESS;
531534 }
532535
--- a/btif/src/btif_av.c
+++ b/btif/src/btif_av.c
@@ -51,6 +51,7 @@
5151 /* Now supports Two AV connections. */
5252 #define BTIF_AV_NUM_CB 2
5353 #define HANDLE_TO_INDEX(x) ((x & BTA_AV_HNDL_MSK) - 1)
54+#define INVALID_INDEX -1
5455
5556 typedef enum {
5657 BTIF_AV_STATE_IDLE = 0x0,
@@ -225,7 +226,7 @@ void btif_av_update_multicast_state(int index);
225226 BOOLEAN btif_av_get_ongoing_multicast();
226227 tBTA_AV_HNDL btif_av_get_playing_device_hdl();
227228 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);
229230 #ifdef BTA_AV_SPLIT_A2DP_ENABLED
230231 BOOLEAN btif_av_is_codec_offload_supported(int codec);
231232 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
14751476 btif_av_is_connected_on_other_idx(index))
14761477 {
14771478 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);
14791480 HAL_CBACK(bt_av_src_callbacks, reconfig_a2dp_trigger_cb, 1,
14801481 &(btif_av_cb[idx].peer_bda));
14811482 }
@@ -2478,7 +2479,9 @@ void btif_av_trigger_dual_handoff(BOOLEAN handoff, BD_ADDR address)
24782479 {
24792480 btif_media_send_reset_vendor_state();
24802481 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)
24822485 {
24832486 HAL_CBACK(bt_av_src_callbacks, reconfig_a2dp_trigger_cb, 1,
24842487 &(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)
28902893 *******************************************************************************/
28912894 bt_status_t btif_av_execute_service(BOOLEAN b_enable)
28922895 {
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 */
29002904
29012905 /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not
29022906 * 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)
29212925 BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback,
29222926 UUID_SERVCLASS_AUDIO_SOURCE);
29232927 }
2928+ BTA_AvUpdateMaxAVClient(btif_max_av_clients);
29242929 }
29252930 else
29262931 {
@@ -2929,7 +2934,13 @@ bt_status_t btif_av_execute_service(BOOLEAN b_enable)
29292934 {
29302935 if (btif_av_cb[i].sm_handle != NULL)
29312936 {
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+ }
29332944 btif_sm_shutdown(btif_av_cb[i].sm_handle);
29342945 btif_av_cb[i].sm_handle = NULL;
29352946 }
@@ -3065,7 +3076,7 @@ BOOLEAN btif_av_is_connected_on_other_idx(int current_index)
30653076 ** Returns BOOLEAN
30663077 **
30673078 *******************************************************************************/
3068-UINT8 btif_av_get_other_connected_idx(int current_index)
3079+int btif_av_get_other_connected_idx(int current_index)
30693080 {
30703081 //return true if other IDx is connected
30713082 btif_sm_state_t state = BTIF_AV_STATE_IDLE;
@@ -3080,7 +3091,7 @@ UINT8 btif_av_get_other_connected_idx(int current_index)
30803091 return i;
30813092 }
30823093 }
3083- return -1;
3094+ return INVALID_INDEX;
30843095 }
30853096
30863097 /*******************************************************************************
@@ -3459,6 +3470,19 @@ BOOLEAN btif_av_get_ongoing_multicast()
34593470 }
34603471 }
34613472
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+
34623486 #ifdef BTA_AV_SPLIT_A2DP_ENABLED
34633487 int btif_av_get_current_playing_dev_idx(void)
34643488 {
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -64,6 +64,8 @@
6464 /******************************************************************************
6565 ** Constants & Macros
6666 ******************************************************************************/
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);}
6769
6870 #define COD_MASK 0x07FF
6971
@@ -855,6 +857,21 @@ static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transpor
855857 *******************************************************************************/
856858 void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
857859 {
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+
858875 /*special handling for HID devices */
859876 /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there
860877 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)
14771494 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
14781495 int addr_type = 0;
14791496 #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]);
14801501
14811502 memset(properties, 0, sizeof(properties));
14821503 /* BD_ADDR */
@@ -1485,7 +1506,14 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
14851506 num_properties++;
14861507 /* BD_NAME */
14871508 /* 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])
14891517 {
14901518 if((check_eir_is_remote_name_short(p_search_data) == TRUE) &&
14911519 (btif_storage_is_device_bonded(&bdaddr) == TRUE))
--- a/btif/src/btif_media_task.c
+++ b/btif/src/btif_media_task.c
@@ -42,7 +42,6 @@
4242 #include <pthread.h>
4343 #include <stdint.h>
4444 #include <stdio.h>
45-#include <dlfcn.h>
4645 #include <string.h>
4746 #include <sys/stat.h>
4847 #include <sys/time.h>
@@ -51,6 +50,12 @@
5150
5251 #include <hardware/bluetooth.h>
5352
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"
5459 #include "bt_utils.h"
5560 #include "a2d_api.h"
5661 #include "a2d_int.h"
@@ -73,12 +78,6 @@
7378 #include "bt_common.h"
7479 #include "device/include/controller.h"
7580 #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"
8281
8382 #if (BTA_AV_INCLUDED == TRUE)
8483 #include "sbc_encoder.h"
@@ -513,20 +512,6 @@ static thread_t *worker_thread;
513512 BOOLEAN bta_av_co_audio_get_codec_config(UINT8 *p_config, UINT16 *p_minmtu, UINT8 type);
514513 UINT8 bta_av_get_current_codec();
515514
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-
530515 extern BOOLEAN bt_split_a2dp_enabled;
531516 extern int btif_max_av_clients;
532517 static uint8_t multicast_query = FALSE;
@@ -1174,6 +1159,7 @@ static void btif_a2dp_encoder_init(tBTA_AV_HNDL hdl)
11741159 bta_av_co_audio_get_codec_config((UINT8*)&aptx_config, &minmtu, A2D_NON_A2DP_MEDIA_CT);
11751160 msg.CodecType = A2D_NON_A2DP_MEDIA_CT;
11761161 msg.SamplingFreq = aptx_config.sampleRate;
1162+ msg.MtuSize = minmtu;
11771163 msg.ChannelMode = aptx_config.channelMode;
11781164 msg.BluetoothVendorID = aptx_config.vendorId;
11791165 msg.BluetoothCodecID = aptx_config.codecId;
@@ -1301,97 +1287,6 @@ bool btif_a2dp_is_media_task_stopped(void)
13011287 return true;
13021288 }
13031289
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-
13951290 bool btif_a2dp_start_media_task(void)
13961291 {
13971292 if (media_task_running != MEDIA_TASK_STATE_OFF)
@@ -1416,9 +1311,6 @@ bool btif_a2dp_start_media_task(void)
14161311 btif_media_thread_handle_cmd,
14171312 NULL);
14181313
1419- // Check if aptX codec is supported
1420- isA2dAptXEnabled = btif_check_and_init_aptX();
1421-
14221314 thread_post(worker_thread, btif_media_thread_init, NULL);
14231315 APPL_TRACE_IMP("## A2DP MEDIA THREAD STARTED ##");
14241316
@@ -1441,8 +1333,13 @@ void btif_a2dp_stop_media_task(void)
14411333 /* make sure no channels are restarted while shutting down */
14421334 media_task_running = MEDIA_TASK_STATE_SHUTTING_DOWN;
14431335
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+ }
14461343
14471344 // Stop timer
14481345 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
21792076 to connect to second other device
21802077 */
21812078 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+ }
21832089 break;
21842090 case BTIF_MEDIA_VS_A2DP_STOP_FAILURE:
21852091 btif_media_cb.tx_stop_initiated = FALSE;
@@ -3349,28 +3255,30 @@ static void btif_media_task_aa_start_tx(void)
33493255 BOOLEAN use_SCMS_T = false;
33503256 #endif
33513257 A2D_AptXCodecType aptX_codec_type = btif_media_task_get_aptX_codec_type();
3258+ BOOLEAN is_24bit_audio = false;
33523259
33533260 BOOLEAN test = false;
33543261 BOOLEAN trace = false;
33553262
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);
33713280 }
3372- } else
3373- {
3281+ } else {
33743282 APPL_TRACE_EVENT("starting timer %dms", BTIF_MEDIA_TIME_TICK);
33753283
33763284 alarm_free(btif_media_cb.media_alarm);
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -1706,6 +1706,19 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
17061706 BTIF_TRACE_IMP ("%s event:%s", __FUNCTION__, dump_rc_event(event));
17071707 switch (event)
17081708 {
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+
17091722 case BTA_AV_RC_OPEN_EVT:
17101723 {
17111724 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)
51985211 }
51995212 #endif
52005213
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+}
52015218 /***************************************************************************
52025219 **
52035220 ** Function cleanup
@@ -5210,14 +5227,8 @@ static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG *pmeta_msg)
52105227 static void cleanup()
52115228 {
52125229 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);
52215232 BTIF_TRACE_EVENT("## RC: %s ## completed", __FUNCTION__);
52225233 }
52235234
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -196,8 +196,12 @@ static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
196196 if(remote_bd_addr)
197197 btif_config_set_str(bdstr,
198198 BTIF_STORAGE_PATH_REMOTE_NAME, value);
199- else btif_config_set_str("Adapter",
199+ else
200+ {
201+ btif_config_set_str("Adapter",
200202 BTIF_STORAGE_KEY_ADAPTER_NAME, value);
203+ btif_config_flush();
204+ }
201205 break;
202206 case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
203207 strncpy(value, (char*)prop->val, prop->len);
--- a/btif/src/btif_util.c
+++ b/btif/src/btif_util.c
@@ -50,6 +50,7 @@
5050 #include "btif_dm.h"
5151 #include "btu.h"
5252 #include "bt_common.h"
53+#include "btif_av.h"
5354
5455 /************************************************************************************
5556 ** Constants & Macros
@@ -492,6 +493,7 @@ const char *dump_rc_event(UINT8 event)
492493 CASE_RETURN_STR(BTA_AV_META_MSG_EVT)
493494 CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT)
494495 CASE_RETURN_STR(BTA_AV_BROWSE_MSG_EVT)
496+ CASE_RETURN_STR(BTIF_AV_CLEANUP_REQ_EVT)
495497 default:
496498 return "UNKNOWN_EVENT";
497499 }
--- a/device/include/controller.h
+++ b/device/include/controller.h
@@ -29,6 +29,10 @@
2929
3030 static const char CONTROLLER_MODULE[] = "controller_module";
3131
32+typedef struct controller_static_t {
33+ void (*enable_soc_logging) (bool value);
34+} controller_static_t;
35+
3236 typedef struct controller_t {
3337 bool (*get_is_ready)(void);
3438
@@ -79,6 +83,8 @@ typedef struct controller_t {
7983 bool (*supports_ble_offload_features)(void);
8084 } controller_t;
8185
86+const controller_static_t *controller_get_static_interface();
87+
8288 const controller_t *controller_get_interface();
8389
8490 const controller_t *controller_get_test_interface(
--- a/device/src/controller.c
+++ b/device/src/controller.c
@@ -29,6 +29,8 @@
2929 #include "hcimsgs.h"
3030 #include "osi/include/future.h"
3131 #include "stack/include/btm_ble_api.h"
32+#include "osi/include/log.h"
33+#include "utils/include/bt_utils.h"
3234
3335 const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x00\x00\x00\x06\x7f" };
3436
@@ -46,6 +48,9 @@ const uint8_t SCO_HOST_BUFFER_SIZE = 0xff;
4648 #define BLE_SUPPORTED_STATES_SIZE 8
4749 #define BLE_SUPPORTED_FEATURES_SIZE 8
4850 #define MAX_LOCAL_SUPPORTED_CODECS_SIZE 8
51+#define UNUSED(x) (void)(x)
52+
53+static bool soc_logging_enabled_via_api;
4954
5055 static const hci_t *hci;
5156 static const hci_packet_factory_t *packet_factory;
@@ -81,6 +86,19 @@ static bool secure_connections_supported;
8186
8287 // Module lifecycle functions
8388
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+
84102 static future_t *start_up(void) {
85103 BT_HDR *response;
86104
@@ -107,9 +125,13 @@ static future_t *start_up(void) {
107125 packet_parser->parse_generic_command_complete(response);
108126
109127 #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+ }
113135 #endif
114136
115137 // Read the local version info off the controller next, including
@@ -288,6 +310,16 @@ EXPORT_SYMBOL const module_t controller_module = {
288310
289311 // Interface functions
290312
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+
291323 static bool get_is_ready(void) {
292324 return readable;
293325 }
@@ -464,6 +496,10 @@ static void set_ble_resolving_list_max_size(int resolving_list_max_size) {
464496 ble_resolving_list_max_size = resolving_list_max_size;
465497 }
466498
499+static const controller_static_t static_interface = {
500+ enable_soc_logging
501+};
502+
467503 static const controller_t interface = {
468504 get_is_ready,
469505
@@ -508,6 +544,10 @@ static const controller_t interface = {
508544 supports_ble_offload_features
509545 };
510546
547+const controller_static_t *controller_get_static_interface() {
548+ return &static_interface;
549+}
550+
511551 const controller_t *controller_get_interface() {
512552 static bool loaded = false;
513553 if (!loaded) {
--- a/osi/src/allocation_tracker.c
+++ b/osi/src/allocation_tracker.c
@@ -66,6 +66,8 @@ void allocation_tracker_init(void) {
6666 if (allocations)
6767 return;
6868
69+ LOG_INFO("allocation_tracker","%s: function addr = %p", __func__,
70+ (void *)allocation_tracker_init);
6971 canary_size = strlen(canary);
7072
7173 pthread_mutex_init(&lock, NULL);
--- a/osi/src/allocator.c
+++ b/osi/src/allocator.c
@@ -21,6 +21,9 @@
2121
2222 #include "osi/include/allocator.h"
2323 #include "osi/include/allocation_tracker.h"
24+#include "osi/include/log.h"
25+
26+#define TAG "bt_allocator"
2427
2528 static const allocator_id_t alloc_allocator_id = 42;
2629
@@ -36,6 +39,11 @@ char *osi_strdup(const char *str) {
3639 size);
3740 if (!new_string)
3841 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
3947
4048 memcpy(new_string, str, size);
4149 return new_string;
@@ -57,6 +65,11 @@ char *osi_strndup(const char *str, size_t len) {
5765 if (!new_string)
5866 return NULL;
5967
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
6073 memcpy(new_string, str, size);
6174 new_string[size] = '\0';
6275 return new_string;
@@ -66,23 +79,49 @@ void *osi_malloc(size_t size) {
6679 size_t real_size = allocation_tracker_resize_for_canary(size);
6780 void *ptr = malloc(real_size);
6881 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
6990 return allocation_tracker_notify_alloc(alloc_allocator_id, ptr, size);
91+#endif
7092 }
7193
7294 void *osi_calloc(size_t size) {
7395 size_t real_size = allocation_tracker_resize_for_canary(size);
7496 void *ptr = calloc(1, real_size);
7597 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
76106 return allocation_tracker_notify_alloc(alloc_allocator_id, ptr, size);
107+#endif
77108 }
78109
79110 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
80115 free(allocation_tracker_notify_free(alloc_allocator_id, ptr));
81116 }
82117
83118 void osi_free_and_reset(void **p_ptr)
84119 {
85120 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
86125 osi_free(*p_ptr);
87126 *p_ptr = NULL;
88127 }
--- a/stack/a2dp/a2d_aptx.c
+++ b/stack/a2dp/a2d_aptx.c
@@ -38,12 +38,32 @@
3838 #include "bt_target.h"
3939
4040 #include <string.h>
41+#include <dlfcn.h>
42+#include "osi/include/thread.h"
4143 #include "bt_utils.h"
4244 #include "a2d_api.h"
4345 #include "a2d_int.h"
4446 #include "a2d_aptx.h"
4547 #include <utils/Log.h>
4648
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+
4767 /******************************************************************************
4868 **
4969 ** Function A2D_BldAptxInfo
@@ -160,3 +180,116 @@ UINT8 a2d_av_aptx_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap)
160180
161181 return status;
162182 }
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+}
--- a/stack/avdt/avdt_api.c
+++ b/stack/avdt/avdt_api.c
@@ -1368,7 +1368,19 @@ UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type,
13681368 return result;
13691369 }
13701370 #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+}
13721384 /******************************************************************************
13731385 **
13741386 ** Function AVDT_SetTraceLevel
--- a/stack/avdt/avdt_ccb_act.c
+++ b/stack/avdt/avdt_ccb_act.c
@@ -178,7 +178,38 @@ void avdt_ccb_hdl_discover_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
178178 p_data->msg.discover_rsp.num_seps++;
179179 }
180180 }
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;
181192
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+ }
182213 /* send response */
183214 avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCOVER_RSP_EVT, p_data);
184215 }
--- a/stack/avdt/avdt_int.h
+++ b/stack/avdt/avdt_int.h
@@ -616,7 +616,8 @@ extern tAVDT_SCB *avdt_scb_by_hdl(UINT8 hdl);
616616 extern UINT8 avdt_scb_verify(tAVDT_CCB *p_ccb, UINT8 state, UINT8 *p_seid, UINT16 num_seid, UINT8 *p_err_code);
617617 extern void avdt_scb_peer_seid_list(tAVDT_MULTI *p_multi);
618618 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);
620621 /* SCB action functions */
621622 extern void avdt_scb_hdl_abort_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
622623 extern void avdt_scb_hdl_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
--- a/stack/avdt/avdt_scb.c
+++ b/stack/avdt/avdt_scb.c
@@ -511,7 +511,7 @@ const tAVDT_SCB_ST_TBL avdt_scb_st_tbl[] = {
511511 avdt_scb_st_closing
512512 };
513513
514-
514+UINT8 max_av_clients = 1;
515515 /*******************************************************************************
516516 **
517517 ** Function avdt_scb_event
@@ -795,3 +795,31 @@ void avdt_scb_peer_seid_list(tAVDT_MULTI *p_multi)
795795 }
796796 }
797797
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+
--- a/stack/btm/btm_acl.c
+++ b/stack/btm/btm_acl.c
@@ -73,6 +73,7 @@ static const UINT8 btm_role_switch_black_list_prefix2[][3] = {{0xfc, 0xc2, 0xde}
7373 ,{0x00, 0x04, 0x3e} /* OBU II Bluetooth dongle */
7474 ,{0x00, 0x23, 0x01} /* Roman R9020 */
7575 ,{0x00, 0x26, 0xb4} /* NAC FORD,2013 Lincoln */
76+ ,{0x1c, 0x48, 0xf9} /* Jabra Storm */
7677 };
7778
7879 /*******************************************************************************
--- a/stack/btm/btm_ble_bgconn.c
+++ b/stack/btm/btm_ble_bgconn.c
@@ -701,6 +701,37 @@ void btm_ble_enqueue_direct_conn_req(void *p_param)
701701 }
702702 /*******************************************************************************
703703 **
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+**
704735 ** Function btm_send_pending_direct_conn
705736 **
706737 ** Description This function send the pending direct connection request in queue
--- a/stack/btm/btm_ble_int.h
+++ b/stack/btm/btm_ble_int.h
@@ -433,6 +433,7 @@ extern void btm_ble_update_link_topology_mask(UINT8 role, BOOLEAN increase);
433433 /* direct connection utility */
434434 extern BOOLEAN btm_send_pending_direct_conn(void);
435435 extern void btm_ble_enqueue_direct_conn_req(void *p_param);
436+extern void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda);
436437
437438 /* BLE address management */
438439 extern void btm_gen_resolvable_private_addr (void *p_cmd_cplt_cback);
--- a/stack/btm/btm_dev.c
+++ b/stack/btm/btm_dev.c
@@ -477,7 +477,6 @@ void btm_consolidate_dev(tBTM_SEC_DEV_REC *p_target_rec)
477477 list_remove(btm_cb.sec_dev_rec, p_dev_rec);
478478
479479 p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
480- break;
481480 }
482481
483482 /* 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)
493492
494493 p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
495494 }
496- break;
497495 }
498496 }
499497 #endif
--- a/stack/gatt/gatt_main.c
+++ b/stack/gatt/gatt_main.c
@@ -249,6 +249,8 @@ BOOLEAN gatt_disconnect (tGATT_TCB *p_tcb)
249249 {
250250 gatt_set_ch_state(p_tcb, GATT_CH_CLOSING);
251251 ret = L2CA_CancelBleConnectReq (p_tcb->peer_bda);
252+ if (!ret)
253+ gatt_set_ch_state(p_tcb, GATT_CH_CLOSE);
252254 }
253255 }
254256 else
--- a/stack/include/a2d_aptx.h
+++ b/stack/include/a2d_aptx.h
@@ -80,7 +80,6 @@ typedef struct
8080 UINT8 future2;
8181 } tA2D_APTX_CIE;
8282
83-
8483 typedef struct {
8584 INT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
8685 INT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
@@ -95,6 +94,8 @@ typedef struct {
9594 extern const char* A2D_APTX_SCHED_LIB_NAME;
9695 extern void *A2dAptXSchedLibHandle;
9796 extern BOOLEAN isA2dAptXEnabled;
97+extern thread_t *A2d_aptx_thread;
98+extern A2D_AptXThreadFn A2d_aptx_thread_fn;
9899
99100 /*****************************************************************************
100101 ** external function declarations
@@ -107,18 +108,20 @@ extern UINT8 A2D_BldAptxInfo(UINT8 media_type, tA2D_APTX_CIE *p_ie,
107108 UINT8 *p_result);
108109 extern UINT8 A2D_ParsAptxInfo(tA2D_APTX_CIE *p_ie, UINT8 *p_info,
109110 BOOLEAN for_caps);
110-extern int (*A2D_aptx_sched_init)(void);
111+extern int (*A2D_aptx_encoder_init)(void);
111112 extern A2D_AptXThreadFn (*A2D_aptx_sched_start)(void *encoder,
112113 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,
116117 A2D_AptXBufferSendFn send_fn,
117118 A2D_AptXSetPriorityFn set_priority_fn,
118119 BOOLEAN test, BOOLEAN trace);
119120 extern BOOLEAN (*A2D_aptx_sched_stop)(void);
120-extern void (*A2D_aptx_sched_deinit)(void);
121+extern void (*A2D_aptx_encoder_deinit)(void);
121122 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();
122125
123126 #ifdef __cplusplus
124127 }
--- a/stack/include/avdt_api.h
+++ b/stack/include/avdt_api.h
@@ -994,6 +994,17 @@ extern UINT16 AVDT_SetMediaBuf(UINT8 handle, UINT8 *p_buf, UINT32 buf_len);
994994 extern UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type,
995995 tAVDT_REPORT_DATA *p_data);
996996
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+
9971008 /******************************************************************************
9981009 **
9991010 ** Function AVDT_SetTraceLevel
--- a/stack/l2cap/l2c_ble.c
+++ b/stack/l2cap/l2c_ble.c
@@ -57,17 +57,17 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda)
5757 /* There can be only one BLE connection request outstanding at a time */
5858 if (btm_ble_get_conn_st() == BLE_CONN_IDLE)
5959 {
60- L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - no connection pending");
60+ L2CAP_TRACE_WARNING ("%s - no connection pending", __func__);
6161 return(FALSE);
6262 }
6363
6464 if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN))
6565 {
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__,
6767 (l2cb.ble_connecting_bda[0]<<24)+(l2cb.ble_connecting_bda[1]<<16)+(l2cb.ble_connecting_bda[2]<<8)+l2cb.ble_connecting_bda[3],
6868 (l2cb.ble_connecting_bda[4]<<8)+l2cb.ble_connecting_bda[5],
6969 (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);
7171 return(FALSE);
7272 }
7373
--- a/stack/l2cap/l2c_csm.c
+++ b/stack/l2cap/l2c_csm.c
@@ -1150,7 +1150,7 @@ static void l2c_csm_open (tL2C_CCB *p_ccb, UINT16 event, void *p_data)
11501150 tempstate = p_ccb->chnl_state;
11511151 tempcfgdone = p_ccb->config_done;
11521152 p_ccb->chnl_state = CST_CONFIG;
1153- p_ccb->config_done &= ~CFG_DONE_MASK;
1153+ p_ccb->config_done &= ~IB_CFG_DONE;
11541154
11551155 alarm_set_on_queue(p_ccb->l2c_ccb_timer,
11561156 L2CAP_CHNL_CFG_TIMEOUT_MS,
--- a/stack/l2cap/l2c_link.c
+++ b/stack/l2cap/l2c_link.c
@@ -59,6 +59,8 @@ static const UINT8 hci_role_switch_black_list_prefix[][3] = {{0x00, 0x26, 0xb4}
5959 ,{0xa4, 0x15, 0x66} /* Motorola Boom */
6060 ,{0xd0, 0x13, 0x1e} /* Samsung keyboard */
6161 ,{0x1c, 0x48, 0xf9} /* Jabra Storm */
62+ ,{0x8f, 0x20, 0xb4} /* BT1719 */
63+ ,{0xa8, 0xb9, 0xb3} /* Sonata CarKit */
6264 };
6365
6466 /*******************************************************************************
--- a/test/blegatt_test/gatt_test.c
+++ b/test/blegatt_test/gatt_test.c
@@ -463,7 +463,7 @@ static void bdt_shutdown(void)
463463 static void config_permissions(void)
464464 {
465465 struct __user_cap_header_struct header;
466- struct __user_cap_data_struct cap;
466+ struct __user_cap_data_struct cap[2];
467467
468468 bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid());
469469
@@ -474,17 +474,25 @@ static void config_permissions(void)
474474 setuid(AID_BLUETOOTH);
475475 setgid(AID_BLUETOOTH);
476476
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]);
488496 setgroups(sizeof(groups)/sizeof(groups[0]), groups);
489497 }
490498
@@ -737,13 +745,16 @@ static int create_cmdjob(char *cmd)
737745 char *job_cmd;
738746
739747 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,
743751 (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;
747758 }
748759
749760 /*******************************************************************************
--- /dev/null
+++ b/test/bluedroidtest/Android.mk
@@ -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)
--- /dev/null
+++ b/test/bluedroidtest/README.txt
@@ -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+
--- /dev/null
+++ b/test/bluedroidtest/bluedroidtest.c
@@ -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+}
--- a/test/l2test_ertm/l2test_ertm.c
+++ b/test/l2test_ertm/l2test_ertm.c
@@ -356,7 +356,7 @@ static void bdt_shutdown(void)
356356 static void config_permissions(void)
357357 {
358358 struct __user_cap_header_struct header;
359- struct __user_cap_data_struct cap;
359+ struct __user_cap_data_struct cap[2];
360360
361361 printf("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid());
362362
@@ -366,18 +366,25 @@ static void config_permissions(void)
366366
367367 setuid(AID_BLUETOOTH);
368368 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]);
381388 setgroups(sizeof(groups)/sizeof(groups[0]), groups);
382389 }
383390
--- a/test/mcap_tool/mcap_tool.c
+++ b/test/mcap_tool/mcap_tool.c
@@ -244,7 +244,7 @@ static void bdt_shutdown(void)
244244 static void config_permissions(void)
245245 {
246246 struct __user_cap_header_struct header;
247- struct __user_cap_data_struct cap;
247+ struct __user_cap_data_struct cap[2];
248248
249249 bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid());
250250
@@ -255,17 +255,25 @@ static void config_permissions(void)
255255 setuid(AID_BLUETOOTH);
256256 setgid(AID_BLUETOOTH);
257257
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]);
269277 setgroups(sizeof(groups)/sizeof(groups[0]), groups);
270278 }
271279
--- a/test/rfcommtest/rfcommtest.c
+++ b/test/rfcommtest/rfcommtest.c
@@ -136,7 +136,7 @@ static int str2bd(char *str, bt_bdaddr_t *addr)
136136 static void config_permissions(void)
137137 {
138138 struct __user_cap_header_struct header;
139- struct __user_cap_data_struct cap;
139+ struct __user_cap_data_struct cap[2];
140140
141141 bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid());
142142
@@ -147,17 +147,25 @@ static void config_permissions(void)
147147 setuid(AID_BLUETOOTH);
148148 setgid(AID_BLUETOOTH);
149149
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]);
161169 setgroups(sizeof(groups)/sizeof(groups[0]), groups);
162170 }
163171 #if 0