* Description: AV implementation
*
*****************************************************************************/
-
-#include "bt_trace.h"
#include <string.h>
-
+#include "bt_trace.h"
#include "bt_defs.h"
#include "esp_bt_defs.h"
#include "esp_a2dp_api.h"
#include "allocator.h"
-
+#include "btc_dm.h"
#include "btc_av.h"
+#include "btc_avrc.h"
#include "btif_util.h"
#include "btc_profile_queue.h"
#include "bta_api.h"
case BTA_AV_RC_FEAT_EVT: \
case BTA_AV_REMOTE_RSP_EVT: \
{ \
- btif_rc_handler(e, d);\
+ btc_rc_handler(e, d);\
}break; \
static BOOLEAN btc_av_state_idle_handler(btif_sm_event_t event, void *data);
/*************************************************************************
** Extern functions
*************************************************************************/
-extern void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data);
-extern BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr);
-extern void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp);
extern tBTA_AV_CO_FUNCTS bta_av_a2d_cos;
/*****************************************************************************
btc_av_connect_req_t connect_req;
UNUSED(tle);
/* is there at least one RC connection - There should be */
- if (btif_rc_get_connected_peer(peer_addr)) {
+ if (btc_rc_get_connected_peer(peer_addr)) {
LOG_DEBUG("%s Issuing connect to the remote RC peer", __FUNCTION__);
/* In case of AVRCP connection request, we will initiate SRC connection */
connect_req.target_bda = (bt_bdaddr_t *)&peer_addr;
tle_av_open_on_rc.param = (UINT32)btc_initiate_av_open_tmr_hdlr;
btu_start_timer(&tle_av_open_on_rc, BTU_TTYPE_USER_FUNC,
BTC_TIMEOUT_AV_OPEN_ON_RC_SECS);
- btif_rc_handler(event, p_data);
+ btc_rc_handler(event, p_data);
break;
case BTA_AV_REMOTE_CMD_EVT:
case BTA_AV_META_MSG_EVT:
case BTA_AV_RC_FEAT_EVT:
case BTA_AV_REMOTE_RSP_EVT:
- btif_rc_handler(event, (tBTA_AV *)p_data);
+ btc_rc_handler(event, (tBTA_AV *)p_data);
break;
case BTA_AV_RC_CLOSE_EVT:
LOG_DEBUG("BTA_AV_RC_CLOSE_EVT: Stopping AV timer.");
btu_stop_timer(&tle_av_open_on_rc);
}
- btif_rc_handler(event, p_data);
+ btc_rc_handler(event, p_data);
break;
default:
btif_sm_change_state(btc_av_cb.sm_handle, av_state);
if (btc_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
+ btc_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
(p_bta_data->open.status == BTA_AV_SUCCESS));
} else if (btc_av_cb.peer_sep == AVDT_TSEP_SRC) {
/* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
+ btc_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
/* Bring up AVRCP connection too */
BTA_AvOpenRc(btc_av_cb.bta_handle);
}
/* Handle the RC_CLOSE event for the cleanup */
case BTA_AV_RC_CLOSE_EVT:
- btif_rc_handler(event, (tBTA_AV *)p_data);
+ btc_rc_handler(event, (tBTA_AV *)p_data);
break;
default:
btc_av_cb.sm_handle =
btif_sm_init((const btif_sm_handler_t *)btc_av_state_handlers, BTC_AV_STATE_IDLE);
- btif_enable_service(BTA_A2DP_SOURCE_SERVICE_ID);
+ btc_dm_enable_service(BTA_A2DP_SOURCE_SERVICE_ID);
#if (BTA_AV_SINK_INCLUDED == TRUE)
- btif_enable_service(BTA_A2DP_SINK_SERVICE_ID);
+ btc_dm_enable_service(BTA_A2DP_SINK_SERVICE_ID);
#endif
btif_a2dp_on_init();
-/******************************************************************************
- *
- * Copyright (C) 2009-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
+// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
/*****************************************************************************
*
- * Filename: btif_rc.c
+ * Filename: btc_avrc.c
*
* Description: Bluetooth AVRC implementation
*
*****************************************************************************/
-// #include <hardware/bluetooth.h>
-// #include <fcntl.h>
#include <string.h>
#include "bta_api.h"
#include "bta_av_api.h"
#include "avrc_defs.h"
#include "gki.h"
-#define LOG_TAG "bt_btif_avrc"
#include "btif_common.h"
#include "btif_util.h"
-#include "btif_av.h"
-#include "bt_rc.h"
+#include "btc_av.h"
+#include "btc_avrc.h"
#include "uinput.h"
#include "esp_avrc_api.h"
#define PLAY_STATUS_PLAYING 1
#define CHECK_RC_CONNECTED \
- BTIF_TRACE_DEBUG("## %s ##", __FUNCTION__); \
- if(btif_rc_cb.rc_connected == FALSE) \
+ LOG_DEBUG("## %s ##", __FUNCTION__); \
+ if(btc_rc_cb.rc_connected == FALSE) \
{ \
- BTIF_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
+ LOG_WARN("Function %s() called when RC is not connected", __FUNCTION__); \
return BT_STATUS_NOT_READY; \
}
#define CHECK_ESP_RC_CONNECTED do { \
- BTIF_TRACE_DEBUG("## %s ##", __FUNCTION__); \
- if (btif_rc_cb.rc_connected == FALSE) { \
- BTIF_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
+ LOG_DEBUG("## %s ##", __FUNCTION__); \
+ if (btc_rc_vb.rc_connected == FALSE) { \
+ LOG_WARN("Function %s() called when RC is not connected", __FUNCTION__); \
return ESP_ERR_INVALID_STATE; \
} \
} while (0)
#define FILL_PDU_QUEUE(index, ctype, label, pending) \
{ \
- btif_rc_cb.rc_pdu_info[index].ctype = ctype; \
- btif_rc_cb.rc_pdu_info[index].label = label; \
- btif_rc_cb.rc_pdu_info[index].is_rsp_pending = pending; \
+ btc_rc_vb.rc_pdu_info[index].ctype = ctype; \
+ btc_rc_vb.rc_pdu_info[index].label = label; \
+ btc_rc_vb.rc_pdu_info[index].is_rsp_pending = pending; \
}
#define SEND_METAMSG_RSP(index, avrc_rsp) \
{ \
- if(btif_rc_cb.rc_pdu_info[index].is_rsp_pending == FALSE) \
+ if(btc_rc_vb.rc_pdu_info[index].is_rsp_pending == FALSE) \
{ \
- BTIF_TRACE_WARNING("%s Not sending response as no PDU was registered", __FUNCTION__); \
+ LOG_WARN("%s Not sending response as no PDU was registered", __FUNCTION__); \
return BT_STATUS_UNHANDLED; \
} \
- send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_pdu_info[index].label, \
- btif_rc_cb.rc_pdu_info[index].ctype, avrc_rsp); \
- btif_rc_cb.rc_pdu_info[index].ctype = 0; \
- btif_rc_cb.rc_pdu_info[index].label = 0; \
- btif_rc_cb.rc_pdu_info[index].is_rsp_pending = FALSE; \
+ send_metamsg_rsp(btc_rc_vb.rc_handle, btc_rc_vb.rc_pdu_info[index].label, \
+ btc_rc_vb.rc_pdu_info[index].ctype, avrc_rsp); \
+ btc_rc_vb.rc_pdu_info[index].ctype = 0; \
+ btc_rc_vb.rc_pdu_info[index].label = 0; \
+ btc_rc_vb.rc_pdu_info[index].is_rsp_pending = FALSE; \
}
/*****************************************************************************
typedef struct {
UINT8 bNotify;
UINT8 label;
-} btif_rc_reg_notifications_t;
+} btc_rc_reg_notifications_t;
typedef struct
{
UINT8 label;
UINT8 ctype;
BOOLEAN is_rsp_pending;
-} btif_rc_cmd_ctxt_t;
+} btc_rc_cmd_ctxt_t;
-/* TODO : Merge btif_rc_reg_notifications_t and btif_rc_cmd_ctxt_t to a single struct */
+/* TODO : Merge btc_rc_reg_notifications_t and btc_rc_cmd_ctxt_t to a single struct */
typedef struct {
BOOLEAN rc_connected;
UINT8 rc_handle;
tBTA_AV_FEAT rc_features;
BD_ADDR rc_addr;
UINT16 rc_pending_play;
- btif_rc_cmd_ctxt_t rc_pdu_info[MAX_CMD_QUEUE_LEN];
- btif_rc_reg_notifications_t rc_notif[MAX_RC_NOTIFICATIONS];
+ btc_rc_cmd_ctxt_t rc_pdu_info[MAX_CMD_QUEUE_LEN];
+ btc_rc_reg_notifications_t rc_notif[MAX_RC_NOTIFICATIONS];
unsigned int rc_volume;
uint8_t rc_vol_label;
-} btif_rc_cb_t;
+} btc_rc_cb_t;
typedef struct {
BOOLEAN in_use;
rc_device_t device;
-#if UINPUT_INCLUDED
-#define MAX_UINPUT_PATHS 3
-static const char* uinput_dev_path[] =
- {"/dev/uinput", "/dev/input/uinput", "/dev/misc/uinput" };
-#endif /* UINPUT_INCLUDED */
static int uinput_fd = -1;
-
static void send_key (int fd, uint16_t key, int pressed);
-#if UINPUT_INCLUDED
-static int send_event (int fd, uint16_t type, uint16_t code, int32_t value);
-static int uinput_driver_check();
-static int uinput_create(char *name);
-static int init_uinput (void);
-static void close_uinput (void);
-#endif /* UINPUT_INCLUDED */
static const struct {
const char *name;
static void release_transaction(UINT8 label);
static rc_transaction_t* get_transaction_by_lbl(UINT8 label);
static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg);
-static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND* p_param, UINT8 ctype, UINT8 label);
-static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label);
-
+static void btc_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND* p_param, UINT8 ctype, UINT8 label);
+static void btc_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label);
+
+static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open);
+static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close);
+static void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp);
+static void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd);
+static void handle_uid_changed_notification(tBTA_AV_META_MSG *pmeta_msg, tAVRC_COMMAND *pavrc_command);
+static void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg);
/*****************************************************************************
** Static variables
******************************************************************************/
-static btif_rc_cb_t btif_rc_cb;
+static btc_rc_cb_t btc_rc_vb;
static btrc_callbacks_t *bt_rc_callbacks = NULL;
// static btrc_ctrl_callbacks_t *bt_rc_ctrl_callbacks = NULL;
static esp_avrc_ct_cb_t bt_rc_ctrl_callback = NULL;
// TODO: need protection against race
-#define BTIF_AVRC_CT_CB_TO_APP(_event, _param) do { \
+#define BTC_AVRC_CT_CB_TO_APP(_event, _param) do { \
if (bt_rc_ctrl_callback) { \
bt_rc_ctrl_callback(_event, _param); \
} \
/*****************************************************************************
** Externs
******************************************************************************/
-#if BTIF_HF_INCLUDED
-extern BOOLEAN btif_hf_call_terminated_recently();
-#else
-BOOLEAN btif_hf_call_terminated_recently()
-{
- return FALSE;
-}
+#if BTC_HF_INCLUDED
+extern BOOLEAN btc_hf_call_terminated_recently();
#endif
-#if 0
-extern BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod);
-#endif
-
-/*****************************************************************************
-** Functions
-******************************************************************************/
-
/*****************************************************************************
** Local uinput helper functions
******************************************************************************/
-#if UINPUT_INCLUDED
-int send_event (int fd, uint16_t type, uint16_t code, int32_t value)
-{
- struct uinput_event event;
- BTIF_TRACE_DEBUG("%s type:%u code:%u value:%d", __FUNCTION__,
- type, code, value);
- memset(&event, 0, sizeof(event));
- event.type = type;
- event.code = code;
- event.value = value;
-
- return write(fd, &event, sizeof(event));
-}
-
-void send_key (int fd, uint16_t key, int pressed)
-{
- BTIF_TRACE_DEBUG("%s fd:%d key:%u pressed:%d", __FUNCTION__,
- fd, key, pressed);
-
- if (fd < 0)
- {
- return;
- }
-
- BTIF_TRACE_DEBUG("AVRCP: Send key %d (%d) fd=%d", key, pressed, fd);
- send_event(fd, EV_KEY, key, pressed);
- send_event(fd, EV_SYN, SYN_REPORT, 0);
-}
-
-/************** uinput related functions **************/
-int uinput_driver_check()
-{
- uint32_t i;
- for (i=0; i < MAX_UINPUT_PATHS; i++)
- {
- if (access(uinput_dev_path[i], O_RDWR) == 0) {
- return 0;
- }
- }
- BTIF_TRACE_ERROR("%s ERROR: uinput device is not in the system", __FUNCTION__);
- return -1;
-}
-
-int uinput_create(char *name)
-{
- struct uinput_dev dev;
- int fd, x = 0;
-
- for(x=0; x < MAX_UINPUT_PATHS; x++)
- {
- fd = open(uinput_dev_path[x], O_RDWR);
- if (fd < 0)
- continue;
- break;
- }
- if (x == MAX_UINPUT_PATHS) {
- BTIF_TRACE_ERROR("%s ERROR: uinput device open failed", __FUNCTION__);
- return -1;
- }
- memset(&dev, 0, sizeof(dev));
- if (name)
- strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE-1);
-
- dev.id.bustype = BUS_BLUETOOTH;
- dev.id.vendor = 0x0000;
- dev.id.product = 0x0000;
- dev.id.version = 0x0000;
-
- if (write(fd, &dev, sizeof(dev)) < 0) {
- BTIF_TRACE_ERROR("%s Unable to write device information", __FUNCTION__);
- close(fd);
- return -1;
- }
-
- ioctl(fd, UI_SET_EVBIT, EV_KEY);
- ioctl(fd, UI_SET_EVBIT, EV_REL);
- ioctl(fd, UI_SET_EVBIT, EV_SYN);
-
- for (x = 0; key_map[x].name != NULL; x++)
- ioctl(fd, UI_SET_KEYBIT, key_map[x].mapped_id);
-
- if (ioctl(fd, UI_DEV_CREATE, NULL) < 0) {
- BTIF_TRACE_ERROR("%s Unable to create uinput device", __FUNCTION__);
- close(fd);
- return -1;
- }
- return fd;
-}
-
-int init_uinput (void)
-{
- char *name = "AVRCP";
-
- BTIF_TRACE_DEBUG("%s", __FUNCTION__);
- uinput_fd = uinput_create(name);
- if (uinput_fd < 0) {
- BTIF_TRACE_ERROR("%s AVRCP: Failed to initialize uinput for %s (%d)",
- __FUNCTION__, name, uinput_fd);
- } else {
- BTIF_TRACE_DEBUG("%s AVRCP: Initialized uinput for %s (fd=%d)",
- __FUNCTION__, name, uinput_fd);
- }
- return uinput_fd;
-}
-
-void close_uinput (void)
-{
- BTIF_TRACE_DEBUG("%s", __FUNCTION__);
- if (uinput_fd > 0) {
- ioctl(uinput_fd, UI_DEV_DESTROY);
-
- close(uinput_fd);
- uinput_fd = -1;
- }
-}
-
-#else /* UINPUT_INCLUDED */
void send_key (int fd, uint16_t key, int pressed)
{
BTIF_TRACE_DEBUG("%s fd:%d key:%u pressed:%d, func not implemented", __FUNCTION__,
return;
}
-#endif /* UINPUT_INCLUDED */
-
-void handle_rc_features()
+static void handle_rc_features()
{
btrc_remote_features_t rc_features = BTRC_FEAT_NONE;
bt_bdaddr_t rc_addr;
- bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
+ bdcpy(rc_addr.address, btc_rc_vb.rc_addr);
// TODO(eisenbach): If devices need to be blacklisted for absolute
// volume, it should be added to device/include/interop_database.h
// For now, everything goes... If blacklisting is necessary, exclude
// the following bit here:
- // btif_rc_cb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
+ // btc_rc_vb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
- if (btif_rc_cb.rc_features & BTA_AV_FEAT_BROWSE)
+ if (btc_rc_vb.rc_features & BTA_AV_FEAT_BROWSE)
{
rc_features |= BTRC_FEAT_BROWSE;
}
- if ( (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL) &&
- (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG))
+ if ( (btc_rc_vb.rc_features & BTA_AV_FEAT_ADV_CTRL) &&
+ (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG))
{
rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME;
}
- if (btif_rc_cb.rc_features & BTA_AV_FEAT_METADATA)
+ if (btc_rc_vb.rc_features & BTA_AV_FEAT_METADATA)
{
rc_features |= BTRC_FEAT_METADATA;
}
- BTIF_TRACE_DEBUG("%s: rc_features=0x%x", __FUNCTION__, rc_features);
+ LOG_DEBUG("%s: rc_features=0x%x", __FUNCTION__, rc_features);
// todo: uncomment the following line when added the AVRC target role
// HAL_CBACK(bt_rc_callbacks, remote_features_cb, &rc_addr, rc_features)
#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
- BTIF_TRACE_DEBUG("Checking for feature flags in btif_rc_handler with label %d",
- btif_rc_cb.rc_vol_label);
+ LOG_DEBUG("Checking for feature flags in btc_rc_handler with label %d",
+ btc_rc_vb.rc_vol_label);
// Register for volume change on connect
- if(btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL &&
- btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
+ if(btc_rc_vb.rc_features & BTA_AV_FEAT_ADV_CTRL &&
+ btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG)
{
rc_transaction_t *p_transaction=NULL;
bt_status_t status = BT_STATUS_NOT_READY;
- if(MAX_LABEL==btif_rc_cb.rc_vol_label)
+ if(MAX_LABEL==btc_rc_vb.rc_vol_label)
{
status=get_transaction(&p_transaction);
}
else
{
- p_transaction=get_transaction_by_lbl(btif_rc_cb.rc_vol_label);
+ p_transaction=get_transaction_by_lbl(btc_rc_vb.rc_vol_label);
if(NULL!=p_transaction)
{
- BTIF_TRACE_DEBUG("register_volumechange already in progress for label %d",
- btif_rc_cb.rc_vol_label);
+ LOG_DEBUG("register_volumechange already in progress for label %d",
+ btc_rc_vb.rc_vol_label);
return;
}
else
if(BT_STATUS_SUCCESS == status && NULL!=p_transaction)
{
- btif_rc_cb.rc_vol_label=p_transaction->lbl;
- register_volumechange(btif_rc_cb.rc_vol_label);
+ btc_rc_vb.rc_vol_label=p_transaction->lbl;
+ register_volumechange(btc_rc_vb.rc_vol_label);
}
}
#endif
* - Description: RC connection event handler
*
***************************************************************************/
-void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
+static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
{
- BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle);
+ LOG_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle);
#if (AVRC_CTLR_INCLUDED == TRUE)
bt_bdaddr_t rc_addr;
#endif
if(p_rc_open->status == BTA_AV_SUCCESS)
{
//check if already some RC is connected
- if (btif_rc_cb.rc_connected)
+ if (btc_rc_vb.rc_connected)
{
- BTIF_TRACE_ERROR("Got RC OPEN in connected state, Connected RC: %d \
- and Current RC: %d", btif_rc_cb.rc_handle,p_rc_open->rc_handle );
- if ((btif_rc_cb.rc_handle != p_rc_open->rc_handle)
- && (bdcmp(btif_rc_cb.rc_addr, p_rc_open->peer_addr)))
+ LOG_ERROR("Got RC OPEN in connected state, Connected RC: %d \
+ and Current RC: %d", btc_rc_vb.rc_handle,p_rc_open->rc_handle );
+ if ((btc_rc_vb.rc_handle != p_rc_open->rc_handle)
+ && (bdcmp(btc_rc_vb.rc_addr, p_rc_open->peer_addr)))
{
- BTIF_TRACE_DEBUG("Got RC connected for some other handle");
+ LOG_DEBUG("Got RC connected for some other handle");
BTA_AvCloseRc(p_rc_open->rc_handle);
return;
}
}
- memcpy(btif_rc_cb.rc_addr, p_rc_open->peer_addr, sizeof(BD_ADDR));
- btif_rc_cb.rc_features = p_rc_open->peer_features;
- btif_rc_cb.rc_vol_label=MAX_LABEL;
- btif_rc_cb.rc_volume=MAX_VOLUME;
+ memcpy(btc_rc_vb.rc_addr, p_rc_open->peer_addr, sizeof(BD_ADDR));
+ btc_rc_vb.rc_features = p_rc_open->peer_features;
+ btc_rc_vb.rc_vol_label=MAX_LABEL;
+ btc_rc_vb.rc_volume=MAX_VOLUME;
- btif_rc_cb.rc_connected = TRUE;
- btif_rc_cb.rc_handle = p_rc_open->rc_handle;
+ btc_rc_vb.rc_connected = TRUE;
+ btc_rc_vb.rc_handle = p_rc_open->rc_handle;
/* on locally initiated connection we will get remote features as part of connect */
- if (btif_rc_cb.rc_features != 0)
+ if (btc_rc_vb.rc_features != 0)
handle_rc_features();
#if UINPUT_INCLUDED
if(uinput_driver_check() == BT_STATUS_SUCCESS)
}
#endif /* UINPUT_INCLUDED */
#if (AVRC_CTLR_INCLUDED == TRUE)
- bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
+ bdcpy(rc_addr.address, btc_rc_vb.rc_addr);
/* report connection state if device is AVRCP target */
- if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG) {
+ if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG) {
esp_avrc_ct_cb_param_t param;
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
param.conn_stat.connected = true;
- param.conn_stat.feat_mask = btif_rc_cb.rc_features;
+ param.conn_stat.feat_mask = btc_rc_vb.rc_features;
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
- BTIF_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
+ BTC_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
}
#endif
}
else
{
- BTIF_TRACE_ERROR("%s Connect failed with error code: %d",
+ LOG_ERROR("%s Connect failed with error code: %d",
__FUNCTION__, p_rc_open->status);
- btif_rc_cb.rc_connected = FALSE;
+ btc_rc_vb.rc_connected = FALSE;
}
}
* - Description: RC disconnection event handler
*
***************************************************************************/
-void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
+static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
{
#if (AVRC_CTLR_INCLUDED == TRUE)
bt_bdaddr_t rc_addr;
tBTA_AV_FEAT features;
#endif
- BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_close->rc_handle);
- if ((p_rc_close->rc_handle != btif_rc_cb.rc_handle)
- && (bdcmp(btif_rc_cb.rc_addr, p_rc_close->peer_addr)))
+ LOG_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_close->rc_handle);
+ if ((p_rc_close->rc_handle != btc_rc_vb.rc_handle)
+ && (bdcmp(btc_rc_vb.rc_addr, p_rc_close->peer_addr)))
{
- BTIF_TRACE_ERROR("Got disconnect of unknown device");
+ LOG_ERROR("Got disconnect of unknown device");
return;
}
- btif_rc_cb.rc_handle = 0;
- btif_rc_cb.rc_connected = FALSE;
- memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
- memset(btif_rc_cb.rc_notif, 0, sizeof(btif_rc_cb.rc_notif));
+ btc_rc_vb.rc_handle = 0;
+ btc_rc_vb.rc_connected = FALSE;
+ memset(btc_rc_vb.rc_addr, 0, sizeof(BD_ADDR));
+ memset(btc_rc_vb.rc_notif, 0, sizeof(btc_rc_vb.rc_notif));
#if (AVRC_CTLR_INCLUDED == TRUE)
- features = btif_rc_cb.rc_features;
+ features = btc_rc_vb.rc_features;
#endif
- btif_rc_cb.rc_features = 0;
- btif_rc_cb.rc_vol_label=MAX_LABEL;
- btif_rc_cb.rc_volume=MAX_VOLUME;
+ btc_rc_vb.rc_features = 0;
+ btc_rc_vb.rc_vol_label=MAX_LABEL;
+ btc_rc_vb.rc_volume=MAX_VOLUME;
init_all_transactions();
#if UINPUT_INCLUDED
close_uinput();
#endif /* UINPUT_INCLUDED */
#if (AVRC_CTLR_INCLUDED == TRUE)
- bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
+ bdcpy(rc_addr.address, btc_rc_vb.rc_addr);
#endif
- memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
+ memset(btc_rc_vb.rc_addr, 0, sizeof(BD_ADDR));
#if (AVRC_CTLR_INCLUDED == TRUE)
/* report connection state if device is AVRCP target */
if (features & BTA_AV_FEAT_RCTG) {
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
param.conn_stat.connected = false;
memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t));
- BTIF_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
+ BTC_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
}
#endif
}
* - Description: Remote control command handler
*
***************************************************************************/
-void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
+static void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
{
const char *status;
int pressed, i;
- BTIF_TRACE_DEBUG("%s: p_remote_cmd->rc_id=%d", __FUNCTION__, p_remote_cmd->rc_id);
+ LOG_DEBUG("%s: p_remote_cmd->rc_id=%d", __FUNCTION__, p_remote_cmd->rc_id);
/* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up this PLAY */
if (p_remote_cmd)
{
/* queue AVRC PLAY if GAVDTP Open notification to app is pending (2 second timer) */
- if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY) && (!btif_av_is_connected()))
+ if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY) && (!btc_av_is_connected()))
{
if (p_remote_cmd->key_state == AVRC_STATE_PRESS)
{
APPL_TRACE_WARNING("%s: AVDT not open, queuing the PLAY command", __FUNCTION__);
- btif_rc_cb.rc_pending_play = TRUE;
+ btc_rc_vb.rc_pending_play = TRUE;
}
return;
}
- if ((p_remote_cmd->rc_id == BTA_AV_RC_PAUSE) && (btif_rc_cb.rc_pending_play))
+ if ((p_remote_cmd->rc_id == BTA_AV_RC_PAUSE) && (btc_rc_vb.rc_pending_play))
{
APPL_TRACE_WARNING("%s: Clear the pending PLAY on PAUSE received", __FUNCTION__);
- btif_rc_cb.rc_pending_play = FALSE;
+ btc_rc_vb.rc_pending_play = FALSE;
return;
}
}
- if ((p_remote_cmd->rc_id == BTA_AV_RC_STOP) && (!btif_av_stream_started_ready()))
+ if ((p_remote_cmd->rc_id == BTA_AV_RC_STOP) && (!btc_av_stream_started_ready()))
{
APPL_TRACE_WARNING("%s: Stream suspended, ignore STOP cmd",__FUNCTION__);
return;
* This fix is to interop with certain carkits which sends an automatic PLAY or PAUSE
* commands right after call ends
*/
- if((p_remote_cmd->rc_id == BTA_AV_RC_PLAY || p_remote_cmd->rc_id == BTA_AV_RC_PAUSE)&&
- (btif_hf_call_terminated_recently() == TRUE)
+ if((p_remote_cmd->rc_id == BTA_AV_RC_PLAY || p_remote_cmd->rc_id == BTA_AV_RC_PAUSE)
+#ifdef BTC_HF_INCLUDED
+ && (btc_hf_call_terminated_recently() == TRUE)
+#endif
#if 0 // temporary hack since no btif_storage module is not ported for now
- && (check_cod( (const bt_bdaddr_t*)&(btif_rc_cb.rc_addr), COD_AV_HEADSETS) != TRUE)
+ && (check_cod( (const bt_bdaddr_t*)&(btc_rc_vb.rc_addr), COD_AV_HEADSETS) != TRUE)
#endif
)
{
- BTIF_TRACE_DEBUG("%s:Dropping the play/Pause command received right after call end cmd:%d",
+ LOG_DEBUG("%s:Dropping the play/Pause command received right after call end cmd:%d",
__FUNCTION__,p_remote_cmd->rc_id);
return;
}
for (i = 0; key_map[i].name != NULL; i++) {
if (p_remote_cmd->rc_id == key_map[i].avrcp) {
- BTIF_TRACE_DEBUG("%s: %s %s", __FUNCTION__, key_map[i].name, status);
+ LOG_DEBUG("%s: %s %s", __FUNCTION__, key_map[i].name, status);
/* MusicPlayer uses a long_press_timeout of 1 second for PLAYPAUSE button
* and maps that to autoshuffle. So if for some reason release for PLAY/PAUSE
*/
if ((key_map[i].release_quirk == 1) && (pressed == 0))
{
- BTIF_TRACE_DEBUG("%s: AVRC %s Release Faked earlier, drowned now",
+ LOG_DEBUG("%s: AVRC %s Release Faked earlier, drowned now",
__FUNCTION__, key_map[i].name);
return;
}
if ((key_map[i].release_quirk == 1) && (pressed == 1))
{
GKI_delay(30); // 30ms
- BTIF_TRACE_DEBUG("%s: AVRC %s Release quirk enabled, send release now",
+ LOG_DEBUG("%s: AVRC %s Release quirk enabled, send release now",
__FUNCTION__, key_map[i].name);
send_key(uinput_fd, key_map[i].mapped_id, 0);
}
}
if (key_map[i].name == NULL)
- BTIF_TRACE_ERROR("%s AVRCP: unknown button 0x%02X %s", __FUNCTION__,
+ LOG_ERROR("%s AVRCP: unknown button 0x%02X %s", __FUNCTION__,
p_remote_cmd->rc_id, status);
}
* - Description: Remote control passthrough response handler
*
***************************************************************************/
-void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
+static void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
{
#if (AVRC_CTLR_INCLUDED == TRUE)
const char *status;
- if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
+ if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG)
{
int key_state;
if (p_remote_rsp->key_state == AVRC_STATE_RELEASE)
key_state = 0;
}
- BTIF_TRACE_DEBUG("%s: rc_id=%d status=%s", __FUNCTION__, p_remote_rsp->rc_id, status);
+ LOG_DEBUG("%s: rc_id=%d status=%s", __FUNCTION__, p_remote_rsp->rc_id, status);
do {
esp_avrc_ct_cb_param_t param;
param.psth_rsp.tl = p_remote_rsp->label;
param.psth_rsp.key_code = p_remote_rsp->rc_id;
param.psth_rsp.key_state = key_state;
- BTIF_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_PASSTHROUGH_RSP_EVT, ¶m);
+ BTC_AVRC_CT_CB_TO_APP(ESP_AVRC_CT_PASSTHROUGH_RSP_EVT, ¶m);
} while (0);
}
else
{
- BTIF_TRACE_ERROR("%s DUT does not support AVRCP controller role", __FUNCTION__);
+ LOG_ERROR("%s DUT does not support AVRCP controller role", __FUNCTION__);
}
#else
- BTIF_TRACE_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
+ LOG_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
#endif
}
-void handle_uid_changed_notification(tBTA_AV_META_MSG *pmeta_msg, tAVRC_COMMAND *pavrc_command)
+static void handle_uid_changed_notification(tBTA_AV_META_MSG *pmeta_msg, tAVRC_COMMAND *pavrc_command)
{
tAVRC_RESPONSE avrc_rsp = {0};
avrc_rsp.rsp.pdu = pavrc_command->pdu;
* - Description: Remote control metamsg command handler (AVRCP 1.3)
*
***************************************************************************/
-void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg)
+static void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg)
{
/* Parse the metamsg command and pass it on to BTL-IFS */
UINT8 scratch_buf[512] = {0};
tAVRC_COMMAND avrc_command = {0};
tAVRC_STS status;
- BTIF_TRACE_EVENT("+ %s", __FUNCTION__);
+ LOG_INFO("+ %s", __FUNCTION__);
if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR)
{
- BTIF_TRACE_WARNING("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode);
+ LOG_WARN("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode);
return;
}
if (pmeta_msg->len < 3)
{
- BTIF_TRACE_WARNING("Invalid length.Opcode: 0x%x, len: 0x%x", pmeta_msg->p_msg->hdr.opcode,
+ LOG_WARN("Invalid length.Opcode: 0x%x, len: 0x%x", pmeta_msg->p_msg->hdr.opcode,
pmeta_msg->len);
return;
}
}
else
{
- BTIF_TRACE_DEBUG("%s:Discard vendor dependent rsp. code: %d label:%d.",
+ LOG_DEBUG("%s:Discard vendor dependent rsp. code: %d label:%d.",
__FUNCTION__, pmeta_msg->code, pmeta_msg->label);
}
return;
}
#else
{
- BTIF_TRACE_DEBUG("%s:Received vendor dependent rsp. code: %d len: %d. Not processing it.",
+ LOG_DEBUG("%s:Received vendor dependent rsp. code: %d len: %d. Not processing it.",
__FUNCTION__, pmeta_msg->code, pmeta_msg->len);
return;
}
}
status=AVRC_ParsCommand(pmeta_msg->p_msg, &avrc_command, scratch_buf, sizeof(scratch_buf));
- BTIF_TRACE_DEBUG("Received vendor command.code,PDU and label: %d, %d,%d",pmeta_msg->code,
+ LOG_DEBUG("Received vendor command.code,PDU and label: %d, %d,%d",pmeta_msg->code,
avrc_command.cmd.pdu, pmeta_msg->label);
if (status != AVRC_STS_NO_ERROR)
{
/* return error */
- BTIF_TRACE_WARNING("%s: Error in parsing received metamsg command. status: 0x%02x",
+ LOG_WARN("%s: Error in parsing received metamsg command. status: 0x%02x",
__FUNCTION__, status);
send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_command.pdu, status);
}
if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION)
{
UINT8 event_id = avrc_command.reg_notif.event_id;
- BTIF_TRACE_EVENT("%s:New register notification received.event_id:%s,label:0x%x,code:%x",
+ LOG_INFO("%s:New register notification received.event_id:%s,label:0x%x,code:%x",
__FUNCTION__,dump_rc_notification_event_id(event_id), pmeta_msg->label,pmeta_msg->code);
- btif_rc_cb.rc_notif[event_id-1].bNotify = TRUE;
- btif_rc_cb.rc_notif[event_id-1].label = pmeta_msg->label;
+ btc_rc_vb.rc_notif[event_id-1].bNotify = TRUE;
+ btc_rc_vb.rc_notif[event_id-1].label = pmeta_msg->label;
if(event_id == AVRC_EVT_UIDS_CHANGE)
{
}
- BTIF_TRACE_EVENT("%s: Passing received metamsg command to app. pdu: %s",
+ LOG_INFO("%s: Passing received metamsg command to app. pdu: %s",
__FUNCTION__, dump_rc_pdu(avrc_command.cmd.pdu));
/* Since handle_rc_metamsg_cmd() itself is called from
- * btif context, no context switching is required. Invoke
- * btif_rc_upstreams_evt directly from here. */
- btif_rc_upstreams_evt((uint16_t)avrc_command.cmd.pdu, &avrc_command, pmeta_msg->code,
+ * btc context, no context switching is required. Invoke
+ * btc_rc_upstreams_evt directly from here. */
+ btc_rc_upstreams_evt((uint16_t)avrc_command.cmd.pdu, &avrc_command, pmeta_msg->code,
pmeta_msg->label);
}
}
/***************************************************************************
**
- ** Function btif_rc_handler
+ ** Function btc_rc_handler
**
** Description RC event handler
**
***************************************************************************/
-void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
+void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
{
- BTIF_TRACE_DEBUG ("%s event:%s", __FUNCTION__, dump_rc_event(event));
+ LOG_DEBUG ("%s event:%s", __FUNCTION__, dump_rc_event(event));
switch (event)
{
case BTA_AV_RC_OPEN_EVT:
{
- BTIF_TRACE_DEBUG("Peer_features:%x", p_data->rc_open.peer_features);
+ LOG_DEBUG("Peer_features:%x", p_data->rc_open.peer_features);
handle_rc_connect( &(p_data->rc_open) );
}break;
case BTA_AV_REMOTE_CMD_EVT:
{
- BTIF_TRACE_DEBUG("rc_id:0x%x key_state:%d", p_data->remote_cmd.rc_id,
+ LOG_DEBUG("rc_id:0x%x key_state:%d", p_data->remote_cmd.rc_id,
p_data->remote_cmd.key_state);
handle_rc_passthrough_cmd( (&p_data->remote_cmd) );
}
#if (AVRC_CTLR_INCLUDED == TRUE)
case BTA_AV_REMOTE_RSP_EVT:
{
- BTIF_TRACE_DEBUG("RSP: rc_id:0x%x key_state:%d", p_data->remote_rsp.rc_id,
+ LOG_DEBUG("RSP: rc_id:0x%x key_state:%d", p_data->remote_rsp.rc_id,
p_data->remote_rsp.key_state);
handle_rc_passthrough_rsp( (&p_data->remote_rsp) );
}
#endif
case BTA_AV_RC_FEAT_EVT:
{
- BTIF_TRACE_DEBUG("Peer_features:%x", p_data->rc_feat.peer_features);
- btif_rc_cb.rc_features = p_data->rc_feat.peer_features;
+ LOG_DEBUG("Peer_features:%x", p_data->rc_feat.peer_features);
+ btc_rc_vb.rc_features = p_data->rc_feat.peer_features;
handle_rc_features();
}
break;
case BTA_AV_META_MSG_EVT:
{
- BTIF_TRACE_DEBUG("BTA_AV_META_MSG_EVT code:%d label:%d", p_data->meta_msg.code,
+ LOG_DEBUG("BTA_AV_META_MSG_EVT code:%d label:%d", p_data->meta_msg.code,
p_data->meta_msg.label);
- BTIF_TRACE_DEBUG(" company_id:0x%x len:%d handle:%d", p_data->meta_msg.company_id,
+ LOG_DEBUG(" company_id:0x%x len:%d handle:%d", p_data->meta_msg.company_id,
p_data->meta_msg.len, p_data->meta_msg.rc_handle);
/* handle the metamsg command */
handle_rc_metamsg_cmd(&(p_data->meta_msg));
}
break;
default:
- BTIF_TRACE_DEBUG("Unhandled RC event : 0x%x", event);
+ LOG_DEBUG("Unhandled RC event : 0x%x", event);
}
}
/***************************************************************************
**
- ** Function btif_rc_get_connected_peer
+ ** Function btc_rc_get_connected_peer
**
** Description Fetches the connected headset's BD_ADDR if any
**
***************************************************************************/
-BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr)
+BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr)
{
- if (btif_rc_cb.rc_connected == TRUE) {
- bdcpy(peer_addr, btif_rc_cb.rc_addr);
+ if (btc_rc_vb.rc_connected == TRUE) {
+ bdcpy(peer_addr, btc_rc_vb.rc_addr);
return TRUE;
}
return FALSE;
/***************************************************************************
**
- ** Function btif_rc_check_handle_pending_play
+ ** Function btc_rc_check_handle_pending_play
**
** Description Clears the queued PLAY command. if bSend is TRUE, forwards to app
**
***************************************************************************/
/* clear the queued PLAY command. if bSend is TRUE, forward to app */
-void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp)
+void btc_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp)
{
UNUSED(peer_addr);
- BTIF_TRACE_DEBUG("%s: bSendToApp=%d", __FUNCTION__, bSendToApp);
- if (btif_rc_cb.rc_pending_play)
+ LOG_DEBUG("%s: bSendToApp=%d", __FUNCTION__, bSendToApp);
+ if (btc_rc_vb.rc_pending_play)
{
if (bSendToApp)
{
APPL_TRACE_DEBUG("%s: Sending queued PLAYED event to app", __FUNCTION__);
memset (&remote_cmd, 0, sizeof(tBTA_AV_REMOTE_CMD));
- remote_cmd.rc_handle = btif_rc_cb.rc_handle;
+ remote_cmd.rc_handle = btc_rc_vb.rc_handle;
remote_cmd.rc_id = AVRC_ID_PLAY;
remote_cmd.hdr.ctype = AVRC_CMD_CTRL;
remote_cmd.hdr.opcode = AVRC_OP_PASS_THRU;
remote_cmd.key_state = AVRC_STATE_RELEASE;
handle_rc_passthrough_cmd( &remote_cmd );
}
- btif_rc_cb.rc_pending_play = FALSE;
+ btc_rc_vb.rc_pending_play = FALSE;
}
}
if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(rc_handle, &avrc_rsp, &p_msg)) )
{
- BTIF_TRACE_DEBUG("%s:Sending error notification to handle:%d. pdu:%s,status:0x%02x",
+ LOG_DEBUG("%s:Sending error notification to handle:%d. pdu:%s,status:0x%02x",
__FUNCTION__, rc_handle, dump_rc_pdu(pdu), status);
BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
}
if (!pmetamsg_resp)
{
- BTIF_TRACE_WARNING("%s: Invalid response received from application", __FUNCTION__);
+ LOG_WARN("%s: Invalid response received from application", __FUNCTION__);
return;
}
- BTIF_TRACE_EVENT("+%s: rc_handle: %d, label: %d, code: 0x%02x, pdu: %s", __FUNCTION__,
+ LOG_INFO("+%s: rc_handle: %d, label: %d, code: 0x%02x, pdu: %s", __FUNCTION__,
rc_handle, label, code, dump_rc_pdu(pmetamsg_resp->rsp.pdu));
if (pmetamsg_resp->rsp.status != AVRC_STS_NO_ERROR)
{
BOOLEAN bSent = FALSE;
UINT8 event_id = pmetamsg_resp->reg_notif.event_id;
- BOOLEAN bNotify = (btif_rc_cb.rc_connected) && (btif_rc_cb.rc_notif[event_id-1].bNotify);
+ BOOLEAN bNotify = (btc_rc_vb.rc_connected) && (btc_rc_vb.rc_notif[event_id-1].bNotify);
/* de-register this notification for a CHANGED response */
- btif_rc_cb.rc_notif[event_id-1].bNotify = FALSE;
- BTIF_TRACE_DEBUG("%s rc_handle: %d. event_id: 0x%02d bNotify:%u", __FUNCTION__,
- btif_rc_cb.rc_handle, event_id, bNotify);
+ btc_rc_vb.rc_notif[event_id-1].bNotify = FALSE;
+ LOG_DEBUG("%s rc_handle: %d. event_id: 0x%02d bNotify:%u", __FUNCTION__,
+ btc_rc_vb.rc_handle, event_id, bNotify);
if (bNotify)
{
BT_HDR *p_msg = NULL;
tAVRC_STS status;
- if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(btif_rc_cb.rc_handle,
+ if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(btc_rc_vb.rc_handle,
pmetamsg_resp, &p_msg)) )
{
- BTIF_TRACE_DEBUG("%s Sending notification to rc_handle: %d. event_id: 0x%02d",
- __FUNCTION__, btif_rc_cb.rc_handle, event_id);
+ LOG_DEBUG("%s Sending notification to rc_handle: %d. event_id: 0x%02d",
+ __FUNCTION__, btc_rc_vb.rc_handle, event_id);
bSent = TRUE;
- BTA_AvMetaRsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
+ BTA_AvMetaRsp(btc_rc_vb.rc_handle, btc_rc_vb.rc_notif[event_id-1].label,
ctype, p_msg);
}
else
{
- BTIF_TRACE_WARNING("%s failed to build metamsg response. status: 0x%02x",
+ LOG_WARN("%s failed to build metamsg response. status: 0x%02x",
__FUNCTION__, status);
}
if (!bSent)
{
- BTIF_TRACE_DEBUG("%s: Notification not sent, as there are no RC connections or the \
+ LOG_DEBUG("%s: Notification not sent, as there are no RC connections or the \
CT has not subscribed for event_id: %s", __FUNCTION__, dump_rc_notification_event_id(event_id));
}
}
}
else
{
- BTIF_TRACE_ERROR("%s: failed to build metamsg response. status: 0x%02x",
+ LOG_ERROR("%s: failed to build metamsg response. status: 0x%02x",
__FUNCTION__, status);
}
}
/*******************************************************************************
**
-** Function btif_rc_upstreams_evt
+** Function btc_rc_upstreams_evt
**
-** Description Executes AVRC UPSTREAMS events in btif context.
+** Description Executes AVRC UPSTREAMS events in btc context.
**
** Returns void
**
*******************************************************************************/
-static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 ctype, UINT8 label)
+static void btc_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 ctype, UINT8 label)
{
- BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
- dump_rc_pdu(pavrc_cmd->pdu), btif_rc_cb.rc_handle, ctype, label);
+ LOG_INFO("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
+ dump_rc_pdu(pavrc_cmd->pdu), btc_rc_vb.rc_handle, ctype, label);
switch (event)
{
case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
{
/* TODO: Add support for Application Settings */
- send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_CMD);
+ send_reject_response (btc_rc_vb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_CMD);
}
break;
case AVRC_PDU_GET_ELEMENT_ATTR:
else if (pavrc_cmd->get_elem_attrs.num_attr == 0xFF)
{
/* 0xff indicates, no attributes requested - reject */
- send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
+ send_reject_response (btc_rc_vb.rc_handle, label, pavrc_cmd->pdu,
AVRC_STS_BAD_PARAM);
return;
}
if(pavrc_cmd->reg_notif.event_id == BTRC_EVT_PLAY_POS_CHANGED &&
pavrc_cmd->reg_notif.param == 0)
{
- BTIF_TRACE_WARNING("%s Device registering position changed with illegal param 0.",
+ LOG_WARN("%s Device registering position changed with illegal param 0.",
__FUNCTION__);
- send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM);
+ send_reject_response (btc_rc_vb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM);
/* de-register this notification for a rejected response */
- btif_rc_cb.rc_notif[BTRC_EVT_PLAY_POS_CHANGED - 1].bNotify = FALSE;
+ btc_rc_vb.rc_notif[BTRC_EVT_PLAY_POS_CHANGED - 1].bNotify = FALSE;
return;
}
HAL_CBACK(bt_rc_callbacks, register_notification_cb, pavrc_cmd->reg_notif.event_id,
case AVRC_PDU_INFORM_DISPLAY_CHARSET:
{
tAVRC_RESPONSE avrc_rsp;
- BTIF_TRACE_EVENT("%s() AVRC_PDU_INFORM_DISPLAY_CHARSET", __FUNCTION__);
- if(btif_rc_cb.rc_connected == TRUE)
+ LOG_INFO("%s() AVRC_PDU_INFORM_DISPLAY_CHARSET", __FUNCTION__);
+ if(btc_rc_vb.rc_connected == TRUE)
{
memset(&(avrc_rsp.inform_charset), 0, sizeof(tAVRC_RSP));
avrc_rsp.inform_charset.opcode=opcode_from_pdu(AVRC_PDU_INFORM_DISPLAY_CHARSET);
avrc_rsp.inform_charset.pdu=AVRC_PDU_INFORM_DISPLAY_CHARSET;
avrc_rsp.inform_charset.status=AVRC_STS_NO_ERROR;
- send_metamsg_rsp(btif_rc_cb.rc_handle, label, ctype, &avrc_rsp);
+ send_metamsg_rsp(btc_rc_vb.rc_handle, label, ctype, &avrc_rsp);
}
}
break;
default:
{
- send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
+ send_reject_response (btc_rc_vb.rc_handle, label, pavrc_cmd->pdu,
(pavrc_cmd->pdu == AVRC_PDU_SEARCH)?AVRC_STS_SEARCH_NOT_SUP:AVRC_STS_BAD_CMD);
return;
}
/*******************************************************************************
**
-** Function btif_rc_upstreams_rsp_evt
+** Function btc_rc_upstreams_rsp_evt
**
-** Description Executes AVRC UPSTREAMS response events in btif context.
+** Description Executes AVRC UPSTREAMS response events in btc context.
**
** Returns void
**
*******************************************************************************/
-static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label)
+static void btc_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label)
{
- BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
- dump_rc_pdu(pavrc_resp->pdu), btif_rc_cb.rc_handle, ctype, label);
+ LOG_INFO("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
+ dump_rc_pdu(pavrc_resp->pdu), btc_rc_vb.rc_handle, ctype, label);
#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
switch (event)
case AVRC_PDU_REGISTER_NOTIFICATION:
{
if(AVRC_RSP_CHANGED==ctype)
- btif_rc_cb.rc_volume=pavrc_resp->reg_notif.param.volume;
+ btc_rc_vb.rc_volume=pavrc_resp->reg_notif.param.volume;
HAL_CBACK(bt_rc_callbacks, volume_change_cb, pavrc_resp->reg_notif.param.volume,ctype)
}
break;
case AVRC_PDU_SET_ABSOLUTE_VOLUME:
{
- BTIF_TRACE_DEBUG("Set absolute volume change event received: volume %d,ctype %d",
+ LOG_DEBUG("Set absolute volume change event received: volume %d,ctype %d",
pavrc_resp->volume.volume,ctype);
if(AVRC_RSP_ACCEPT==ctype)
- btif_rc_cb.rc_volume=pavrc_resp->volume.volume;
+ btc_rc_vb.rc_volume=pavrc_resp->volume.volume;
HAL_CBACK(bt_rc_callbacks,volume_change_cb,pavrc_resp->volume.volume,ctype)
}
break;
** AVRCP API Functions
************************************************************************************/
-/*******************************************************************************
-**
-** Function init
-**
-** Description Initializes the AVRC interface
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-static bt_status_t init(btrc_callbacks_t* callbacks )
-{
- BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
- bt_status_t result = BT_STATUS_SUCCESS;
-
- if (bt_rc_callbacks)
- return BT_STATUS_DONE;
-
- bt_rc_callbacks = callbacks;
- memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
- btif_rc_cb.rc_vol_label=MAX_LABEL;
- btif_rc_cb.rc_volume=MAX_VOLUME;
- lbl_init();
-
- return result;
-}
-
-
/*******************************************************************************
**
** Function esp_avrc_ct_register_callback
*******************************************************************************/
esp_err_t esp_avrc_ct_init(void)
{
- BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
+ LOG_INFO("## %s ##", __FUNCTION__);
esp_err_t result = ESP_OK;
- memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
- btif_rc_cb.rc_vol_label=MAX_LABEL;
- btif_rc_cb.rc_volume=MAX_VOLUME;
+ memset (&btc_rc_vb, 0, sizeof(btc_rc_vb));
+ btc_rc_vb.rc_vol_label=MAX_LABEL;
+ btc_rc_vb.rc_volume=MAX_VOLUME;
lbl_init();
return result;
}
-/***************************************************************************
-**
-** Function get_play_status_rsp
-**
-** Description Returns the current play status.
-** This method is called in response to
-** GetPlayStatus request.
-**
-** Returns bt_status_t
-**
-***************************************************************************/
-static bt_status_t get_play_status_rsp(btrc_play_status_t play_status, uint32_t song_len,
- uint32_t song_pos)
-{
- tAVRC_RESPONSE avrc_rsp;
- CHECK_RC_CONNECTED
- memset(&(avrc_rsp.get_play_status), 0, sizeof(tAVRC_GET_PLAY_STATUS_RSP));
- avrc_rsp.get_play_status.song_len = song_len;
- avrc_rsp.get_play_status.song_pos = song_pos;
- avrc_rsp.get_play_status.play_status = play_status;
-
- avrc_rsp.get_play_status.pdu = AVRC_PDU_GET_PLAY_STATUS;
- avrc_rsp.get_play_status.opcode = opcode_from_pdu(AVRC_PDU_GET_PLAY_STATUS);
- avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
- /* Send the response */
- SEND_METAMSG_RSP(IDX_GET_PLAY_STATUS_RSP, &avrc_rsp);
- return BT_STATUS_SUCCESS;
-}
-
-/***************************************************************************
-**
-** Function get_element_attr_rsp
-**
-** Description Returns the current songs' element attributes
-** in text.
-**
-** Returns bt_status_t
-**
-***************************************************************************/
-static bt_status_t get_element_attr_rsp(uint8_t num_attr, btrc_element_attr_val_t *p_attrs)
-{
- tAVRC_RESPONSE avrc_rsp;
- UINT32 i;
- tAVRC_ATTR_ENTRY element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
- CHECK_RC_CONNECTED
- memset(element_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr);
-
- if (num_attr == 0)
- {
- avrc_rsp.get_play_status.status = AVRC_STS_BAD_PARAM;
- }
- else
- {
- for (i=0; i<num_attr; i++) {
- element_attrs[i].attr_id = p_attrs[i].attr_id;
- element_attrs[i].name.charset_id = AVRC_CHARSET_ID_UTF8;
- element_attrs[i].name.str_len = (UINT16)strlen((char *)p_attrs[i].text);
- element_attrs[i].name.p_str = p_attrs[i].text;
- BTIF_TRACE_DEBUG("%s attr_id:0x%x, charset_id:0x%x, str_len:%d, str:%s",
- __FUNCTION__, (unsigned int)element_attrs[i].attr_id,
- element_attrs[i].name.charset_id, element_attrs[i].name.str_len,
- element_attrs[i].name.p_str);
- }
- avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
- }
- avrc_rsp.get_elem_attrs.num_attr = num_attr;
- avrc_rsp.get_elem_attrs.p_attrs = element_attrs;
- avrc_rsp.get_elem_attrs.pdu = AVRC_PDU_GET_ELEMENT_ATTR;
- avrc_rsp.get_elem_attrs.opcode = opcode_from_pdu(AVRC_PDU_GET_ELEMENT_ATTR);
- /* Send the response */
- SEND_METAMSG_RSP(IDX_GET_ELEMENT_ATTR_RSP, &avrc_rsp);
- return BT_STATUS_SUCCESS;
-}
-
-/***************************************************************************
-**
-** Function register_notification_rsp
-**
-** Description Response to the register notification request.
-** in text.
-**
-** Returns bt_status_t
-**
-***************************************************************************/
-static bt_status_t register_notification_rsp(btrc_event_id_t event_id,
- btrc_notification_type_t type, btrc_register_notification_t *p_param)
-{
- tAVRC_RESPONSE avrc_rsp;
- CHECK_RC_CONNECTED
- BTIF_TRACE_EVENT("## %s ## event_id:%s", __FUNCTION__, dump_rc_notification_event_id(event_id));
- if (btif_rc_cb.rc_notif[event_id-1].bNotify == FALSE)
- {
- BTIF_TRACE_ERROR("Avrcp Event id not registered: event_id = %x", event_id);
- return BT_STATUS_NOT_READY;
- }
- memset(&(avrc_rsp.reg_notif), 0, sizeof(tAVRC_REG_NOTIF_RSP));
- avrc_rsp.reg_notif.event_id = event_id;
-
- switch(event_id)
- {
- case BTRC_EVT_PLAY_STATUS_CHANGED:
- avrc_rsp.reg_notif.param.play_status = p_param->play_status;
- if (avrc_rsp.reg_notif.param.play_status == PLAY_STATUS_PLAYING)
- btif_av_clear_remote_suspend_flag();
- break;
- case BTRC_EVT_TRACK_CHANGE:
- memcpy(&(avrc_rsp.reg_notif.param.track), &(p_param->track), sizeof(btrc_uid_t));
- break;
- case BTRC_EVT_PLAY_POS_CHANGED:
- avrc_rsp.reg_notif.param.play_pos = p_param->song_pos;
- break;
- default:
- BTIF_TRACE_WARNING("%s : Unhandled event ID : 0x%x", __FUNCTION__, event_id);
- return BT_STATUS_UNHANDLED;
- }
-
- avrc_rsp.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
- avrc_rsp.reg_notif.opcode = opcode_from_pdu(AVRC_PDU_REGISTER_NOTIFICATION);
- avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
-
- /* Send the response. */
- send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
- ((type == BTRC_NOTIFICATION_TYPE_INTERIM)?AVRC_CMD_NOTIF:AVRC_RSP_CHANGED), &avrc_rsp);
- return BT_STATUS_SUCCESS;
-}
-
-/***************************************************************************
-**
-** Function set_volume
-**
-** Description Send current volume setting to remote side.
-** Support limited to SetAbsoluteVolume
-** This can be enhanced to support Relative Volume (AVRCP 1.0).
-** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN
-** as opposed to absolute volume level
-** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
-**
-** Returns bt_status_t
-**
-***************************************************************************/
-static bt_status_t set_volume(uint8_t volume)
-{
- BTIF_TRACE_DEBUG("%s", __FUNCTION__);
- CHECK_RC_CONNECTED
- tAVRC_STS status = BT_STATUS_UNSUPPORTED;
- rc_transaction_t *p_transaction=NULL;
-
- if(btif_rc_cb.rc_volume==volume)
- {
- status=BT_STATUS_DONE;
- BTIF_TRACE_ERROR("%s: volume value already set earlier: 0x%02x",__FUNCTION__, volume);
- return status;
- }
-
- if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG) &&
- (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL))
- {
- tAVRC_COMMAND avrc_cmd = {0};
- BT_HDR *p_msg = NULL;
-
- BTIF_TRACE_DEBUG("%s: Peer supports absolute volume. newVolume=%d", __FUNCTION__, volume);
- avrc_cmd.volume.opcode = AVRC_OP_VENDOR;
- avrc_cmd.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME;
- avrc_cmd.volume.status = AVRC_STS_NO_ERROR;
- avrc_cmd.volume.volume = volume;
-
- if (AVRC_BldCommand(&avrc_cmd, &p_msg) == AVRC_STS_NO_ERROR)
- {
- bt_status_t tran_status=get_transaction(&p_transaction);
- if(BT_STATUS_SUCCESS == tran_status && NULL!=p_transaction)
- {
- BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
- __FUNCTION__,p_transaction->lbl);
- BTA_AvMetaCmd(btif_rc_cb.rc_handle,p_transaction->lbl, AVRC_CMD_CTRL, p_msg);
- status = BT_STATUS_SUCCESS;
- }
- else
- {
- if(NULL!=p_msg)
- GKI_freebuf(p_msg);
- BTIF_TRACE_ERROR("%s: failed to obtain transaction details. status: 0x%02x",
- __FUNCTION__, tran_status);
- status = BT_STATUS_FAIL;
- }
- }
- else
- {
- BTIF_TRACE_ERROR("%s: failed to build absolute volume command. status: 0x%02x",
- __FUNCTION__, status);
- status = BT_STATUS_FAIL;
- }
- }
- else
- status=BT_STATUS_NOT_READY;
- return status;
-}
-
/***************************************************************************
**
tAVRC_STS BldResp=AVRC_STS_BAD_CMD;
rc_transaction_t *p_transaction=NULL;
- BTIF_TRACE_DEBUG("%s called with label:%d",__FUNCTION__,lbl);
+ LOG_DEBUG("%s called with label:%d",__FUNCTION__,lbl);
avrc_cmd.cmd.opcode=0x00;
avrc_cmd.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
p_transaction=get_transaction_by_lbl(lbl);
if(NULL!=p_transaction)
{
- BTA_AvMetaCmd(btif_rc_cb.rc_handle,p_transaction->lbl, AVRC_CMD_NOTIF, p_msg);
- BTIF_TRACE_DEBUG("%s:BTA_AvMetaCmd called",__FUNCTION__);
+ BTA_AvMetaCmd(btc_rc_vb.rc_handle,p_transaction->lbl, AVRC_CMD_NOTIF, p_msg);
+ LOG_DEBUG("%s:BTA_AvMetaCmd called",__FUNCTION__);
}
else
{
if(NULL!=p_msg)
GKI_freebuf(p_msg);
- BTIF_TRACE_ERROR("%s transaction not obtained with label: %d",__FUNCTION__,lbl);
+ LOG_ERROR("%s transaction not obtained with label: %d",__FUNCTION__,lbl);
}
}
else
- BTIF_TRACE_ERROR("%s failed to build command:%d",__FUNCTION__,BldResp);
+ LOG_ERROR("%s failed to build command:%d",__FUNCTION__,BldResp);
}
|| AVRC_RSP_REJ==pmeta_msg->code || AVRC_RSP_NOT_IMPL==pmeta_msg->code))
{
status=AVRC_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, sizeof(scratch_buf));
- BTIF_TRACE_DEBUG("%s: code %d,event ID %d,PDU %x,parsing status %d, label:%d",
+ LOG_DEBUG("%s: code %d,event ID %d,PDU %x,parsing status %d, label:%d",
__FUNCTION__,pmeta_msg->code,avrc_response.reg_notif.event_id,avrc_response.reg_notif.pdu,
status, pmeta_msg->label);
{
if(AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
&& AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
- && btif_rc_cb.rc_vol_label==pmeta_msg->label)
+ && btc_rc_vb.rc_vol_label==pmeta_msg->label)
{
- btif_rc_cb.rc_vol_label=MAX_LABEL;
- release_transaction(btif_rc_cb.rc_vol_label);
+ btc_rc_vb.rc_vol_label=MAX_LABEL;
+ release_transaction(btc_rc_vb.rc_vol_label);
}
else if(AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
{
}
else if(AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
&& AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
- && btif_rc_cb.rc_vol_label!=pmeta_msg->label)
+ && btc_rc_vb.rc_vol_label!=pmeta_msg->label)
{
// Just discard the message, if the device sends back with an incorrect label
- BTIF_TRACE_DEBUG("%s:Discarding register notfn in rsp.code: %d and label %d",
+ LOG_DEBUG("%s:Discarding register notfn in rsp.code: %d and label %d",
__FUNCTION__, pmeta_msg->code, pmeta_msg->label);
return;
}
}
else
{
- BTIF_TRACE_DEBUG("%s:Received vendor dependent in adv ctrl rsp. code: %d len: %d. Not processing it.",
+ LOG_DEBUG("%s:Received vendor dependent in adv ctrl rsp. code: %d len: %d. Not processing it.",
__FUNCTION__, pmeta_msg->code, pmeta_msg->len);
return;
}
{
/* re-register for volume change notification */
// Do not re-register for rejected case, as it might get into endless loop
- register_volumechange(btif_rc_cb.rc_vol_label);
+ register_volumechange(btc_rc_vb.rc_vol_label);
}
else if(AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
{
release_transaction(pmeta_msg->label);
}
- BTIF_TRACE_EVENT("%s: Passing received metamsg response to app. pdu: %s",
+ LOG_INFO("%s: Passing received metamsg response to app. pdu: %s",
__FUNCTION__, dump_rc_pdu(avrc_response.pdu));
- btif_rc_upstreams_rsp_evt((uint16_t)avrc_response.rsp.pdu, &avrc_response, pmeta_msg->code,
+ btc_rc_upstreams_rsp_evt((uint16_t)avrc_response.rsp.pdu, &avrc_response, pmeta_msg->code,
pmeta_msg->label);
}
-/***************************************************************************
-**
-** Function cleanup
-**
-** Description Closes the AVRC interface
-**
-** Returns void
-**
-***************************************************************************/
-static void cleanup()
-{
- BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
-#if UINPUT_INCLUDED
- close_uinput();
-#endif /* UINPUT_INCLUDED */
- if (bt_rc_callbacks)
- {
- bt_rc_callbacks = NULL;
- }
- memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
- lbl_destroy();
- BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
-}
-
/***************************************************************************
**
** Function cleanup_ctrl
***************************************************************************/
void esp_avrc_ct_deinit(void)
{
- BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
+ LOG_INFO("## %s ##", __FUNCTION__);
if (bt_rc_ctrl_callback)
{
bt_rc_ctrl_callback = NULL;
}
- memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
+ memset(&btc_rc_vb, 0, sizeof(btc_rc_cb_t));
lbl_destroy();
- BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
+ LOG_INFO("## %s ## completed", __FUNCTION__);
}
esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state)
}
#if (AVRC_CTLR_INCLUDED == TRUE)
CHECK_ESP_RC_CONNECTED;
- BTIF_TRACE_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
+ LOG_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
key_code, key_state);
- if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
+ if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG)
{
- BTA_AvRemoteCmd(btif_rc_cb.rc_handle, tl,
+ BTA_AvRemoteCmd(btc_rc_vb.rc_handle, tl,
(tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state);
status = BT_STATUS_SUCCESS;
- BTIF_TRACE_EVENT("%s: succesfully sent passthrough command to BTA", __FUNCTION__);
+ LOG_INFO("%s: succesfully sent passthrough command to BTA", __FUNCTION__);
}
else
{
status = BT_STATUS_FAIL;
- BTIF_TRACE_DEBUG("%s: feature not supported", __FUNCTION__);
+ LOG_DEBUG("%s: feature not supported", __FUNCTION__);
}
#else
- BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
+ LOG_DEBUG("%s: feature not enabled", __FUNCTION__);
#endif
switch (status) {
}
}
-#if 0
-static const btrc_interface_t bt_rc_interface = {
- sizeof(bt_rc_interface),
- init,
- get_play_status_rsp,
- NULL, /* list_player_app_attr_rsp */
- NULL, /* list_player_app_value_rsp */
- NULL, /* get_player_app_value_rsp */
- NULL, /* get_player_app_attr_text_rsp */
- NULL, /* get_player_app_value_text_rsp */
- get_element_attr_rsp,
- NULL, /* set_player_app_value_rsp */
- register_notification_rsp,
- set_volume,
- cleanup,
-};
-
-/*******************************************************************************
-**
-** Function btif_rc_get_interface
-**
-** Description Get the AVRCP Target callback interface
-**
-** Returns btav_interface_t
-**
-*******************************************************************************/
-const btrc_interface_t *btif_rc_get_interface(void)
-{
- BTIF_TRACE_EVENT("%s", __FUNCTION__);
- return &bt_rc_interface;
-}
-
-#endif /* #if 0*/
-
/*******************************************************************************
** Function initialize_transaction
**
else
{
transaction = &(device.transaction[lbl]);
- BTIF_TRACE_DEBUG("%s: Got transaction.label: %d",__FUNCTION__,lbl);
+ LOG_DEBUG("%s: Got transaction.label: %d",__FUNCTION__,lbl);
}
}
{
if (FALSE==device.transaction[i].in_use)
{
- BTIF_TRACE_DEBUG("%s:Got transaction.label: %d",__FUNCTION__,device.transaction[i].lbl);
+ LOG_DEBUG("%s:Got transaction.label: %d",__FUNCTION__,device.transaction[i].lbl);
device.transaction[i].in_use = TRUE;
*ptransaction = &(device.transaction[i]);
result = BT_STATUS_SUCCESS;
/* If the transaction is in use... */
if (transaction != NULL)
{
- BTIF_TRACE_DEBUG("%s: lbl: %d", __FUNCTION__, lbl);
+ LOG_DEBUG("%s: lbl: %d", __FUNCTION__, lbl);
initialize_transaction(lbl);
}
}
--- /dev/null
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __BTC_AVRC_H__
+#define __BTC_AVRC_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "bt_defs.h"
+#include "bt_types.h"
+#include "bta_av_api.h"
+
+/* Macros */
+#define BTRC_MAX_ATTR_STR_LEN 255
+#define BTRC_UID_SIZE 8
+#define BTRC_MAX_APP_SETTINGS 8
+#define BTRC_MAX_FOLDER_DEPTH 4
+#define BTRC_MAX_APP_ATTR_SIZE 16
+#define BTRC_MAX_ELEM_ATTR_SIZE 7
+
+typedef uint8_t btrc_uid_t[BTRC_UID_SIZE];
+
+typedef enum {
+ BTRC_FEAT_NONE = 0x00, /* AVRCP 1.0 */
+ BTRC_FEAT_METADATA = 0x01, /* AVRCP 1.3 */
+ BTRC_FEAT_ABSOLUTE_VOLUME = 0x02, /* Supports TG role and volume sync */
+ BTRC_FEAT_BROWSE = 0x04, /* AVRCP 1.4 and up, with Browsing support */
+} btrc_remote_features_t;
+
+typedef enum {
+ BTRC_PLAYSTATE_STOPPED = 0x00, /* Stopped */
+ BTRC_PLAYSTATE_PLAYING = 0x01, /* Playing */
+ BTRC_PLAYSTATE_PAUSED = 0x02, /* Paused */
+ BTRC_PLAYSTATE_FWD_SEEK = 0x03, /* Fwd Seek*/
+ BTRC_PLAYSTATE_REV_SEEK = 0x04, /* Rev Seek*/
+ BTRC_PLAYSTATE_ERROR = 0xFF, /* Error */
+} btrc_play_status_t;
+
+typedef enum {
+ BTRC_EVT_PLAY_STATUS_CHANGED = 0x01,
+ BTRC_EVT_TRACK_CHANGE = 0x02,
+ BTRC_EVT_TRACK_REACHED_END = 0x03,
+ BTRC_EVT_TRACK_REACHED_START = 0x04,
+ BTRC_EVT_PLAY_POS_CHANGED = 0x05,
+ BTRC_EVT_APP_SETTINGS_CHANGED = 0x08,
+} btrc_event_id_t;
+
+typedef enum {
+ BTRC_NOTIFICATION_TYPE_INTERIM = 0,
+ BTRC_NOTIFICATION_TYPE_CHANGED = 1,
+} btrc_notification_type_t;
+
+typedef enum {
+ BTRC_PLAYER_ATTR_EQUALIZER = 0x01,
+ BTRC_PLAYER_ATTR_REPEAT = 0x02,
+ BTRC_PLAYER_ATTR_SHUFFLE = 0x03,
+ BTRC_PLAYER_ATTR_SCAN = 0x04,
+} btrc_player_attr_t;
+
+typedef enum {
+ BTRC_MEDIA_ATTR_TITLE = 0x01,
+ BTRC_MEDIA_ATTR_ARTIST = 0x02,
+ BTRC_MEDIA_ATTR_ALBUM = 0x03,
+ BTRC_MEDIA_ATTR_TRACK_NUM = 0x04,
+ BTRC_MEDIA_ATTR_NUM_TRACKS = 0x05,
+ BTRC_MEDIA_ATTR_GENRE = 0x06,
+ BTRC_MEDIA_ATTR_PLAYING_TIME = 0x07,
+} btrc_media_attr_t;
+
+typedef enum {
+ BTRC_PLAYER_VAL_OFF_REPEAT = 0x01,
+ BTRC_PLAYER_VAL_SINGLE_REPEAT = 0x02,
+ BTRC_PLAYER_VAL_ALL_REPEAT = 0x03,
+ BTRC_PLAYER_VAL_GROUP_REPEAT = 0x04
+} btrc_player_repeat_val_t;
+
+typedef enum {
+ BTRC_PLAYER_VAL_OFF_SHUFFLE = 0x01,
+ BTRC_PLAYER_VAL_ALL_SHUFFLE = 0x02,
+ BTRC_PLAYER_VAL_GROUP_SHUFFLE = 0x03
+} btrc_player_shuffle_val_t;
+
+typedef enum {
+ BTRC_STS_BAD_CMD = 0x00, /* Invalid command */
+ BTRC_STS_BAD_PARAM = 0x01, /* Invalid parameter */
+ BTRC_STS_NOT_FOUND = 0x02, /* Specified parameter is wrong or not found */
+ BTRC_STS_INTERNAL_ERR = 0x03, /* Internal Error */
+ BTRC_STS_NO_ERROR = 0x04 /* Operation Success */
+} btrc_status_t;
+
+typedef struct {
+ uint8_t num_attr;
+ uint8_t attr_ids[BTRC_MAX_APP_SETTINGS];
+ uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
+} btrc_player_settings_t;
+
+typedef union
+{
+ btrc_play_status_t play_status;
+ btrc_uid_t track; /* queue position in NowPlaying */
+ uint32_t song_pos;
+ btrc_player_settings_t player_setting;
+} btrc_register_notification_t;
+
+typedef struct {
+ uint8_t id; /* can be attr_id or value_id */
+ uint8_t text[BTRC_MAX_ATTR_STR_LEN];
+} btrc_player_setting_text_t;
+
+typedef struct {
+ uint32_t attr_id;
+ uint8_t text[BTRC_MAX_ATTR_STR_LEN];
+} btrc_element_attr_val_t;
+
+/** Callback for the controller's supported feautres */
+typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
+ btrc_remote_features_t features);
+
+/** Callback for play status request */
+typedef void (* btrc_get_play_status_callback)();
+
+/** Callback for list player application attributes (Shuffle, Repeat,...) */
+typedef void (* btrc_list_player_app_attr_callback)();
+
+/** Callback for list player application attributes (Shuffle, Repeat,...) */
+typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id);
+
+/** Callback for getting the current player application settings value
+** num_attr: specifies the number of attribute ids contained in p_attrs
+*/
+typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
+
+/** Callback for getting the player application settings attributes' text
+** num_attr: specifies the number of attribute ids contained in p_attrs
+*/
+typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
+
+/** Callback for getting the player application settings values' text
+** num_attr: specifies the number of value ids contained in p_vals
+*/
+typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id, uint8_t num_val, uint8_t *p_vals);
+
+/** Callback for setting the player application settings values */
+typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals);
+
+/** Callback to fetch the get element attributes of the current song
+** num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs);
+
+/** Callback for register notification (Play state change/track change/...)
+** param: Is only valid if event_id is BTRC_EVT_PLAY_POS_CHANGED
+*/
+typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param);
+
+/* AVRCP 1.4 Enhancements */
+/** Callback for volume change on CT
+** volume: Current volume setting on the CT (0-127)
+*/
+typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype);
+
+/** Callback for passthrough commands */
+typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state);
+
+/** BT-RC Target callback structure. */
+typedef struct {
+ /** set to sizeof(BtRcCallbacks) */
+ size_t size;
+ btrc_remote_features_callback remote_features_cb;
+ btrc_get_play_status_callback get_play_status_cb;
+ btrc_list_player_app_attr_callback list_player_app_attr_cb;
+ btrc_list_player_app_values_callback list_player_app_values_cb;
+ btrc_get_player_app_value_callback get_player_app_value_cb;
+ btrc_get_player_app_attrs_text_callback get_player_app_attrs_text_cb;
+ btrc_get_player_app_values_text_callback get_player_app_values_text_cb;
+ btrc_set_player_app_value_callback set_player_app_value_cb;
+ btrc_get_element_attr_callback get_element_attr_cb;
+ btrc_register_notification_callback register_notification_cb;
+ btrc_volume_change_callback volume_change_cb;
+ btrc_passthrough_cmd_callback passthrough_cmd_cb;
+} btrc_callbacks_t;
+
+/** Represents the standard BT-RC AVRCP Target interface. */
+typedef struct {
+
+ /** set to sizeof(BtRcInterface) */
+ size_t size;
+ /**
+ * Register the BtRc callbacks
+ */
+ bt_status_t (*init)( btrc_callbacks_t* callbacks );
+
+ /** Respose to GetPlayStatus request. Contains the current
+ ** 1. Play status
+ ** 2. Song duration/length
+ ** 3. Song position
+ */
+ bt_status_t (*get_play_status_rsp)( btrc_play_status_t play_status, uint32_t song_len, uint32_t song_pos);
+
+ /** Lists the support player application attributes (Shuffle/Repeat/...)
+ ** num_attr: Specifies the number of attributes contained in the pointer p_attrs
+ */
+ bt_status_t (*list_player_app_attr_rsp)( int num_attr, btrc_player_attr_t *p_attrs);
+
+ /** Lists the support player application attributes (Shuffle Off/On/Group)
+ ** num_val: Specifies the number of values contained in the pointer p_vals
+ */
+ bt_status_t (*list_player_app_value_rsp)( int num_val, uint8_t *p_vals);
+
+ /** Returns the current application attribute values for each of the specified attr_id */
+ bt_status_t (*get_player_app_value_rsp)( btrc_player_settings_t *p_vals);
+
+ /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
+ ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
+ */
+ bt_status_t (*get_player_app_attr_text_rsp)( int num_attr, btrc_player_setting_text_t *p_attrs);
+
+ /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
+ ** num_attr: Specifies the number of attribute values' text contained in the pointer p_vals
+ */
+ bt_status_t (*get_player_app_value_text_rsp)( int num_val, btrc_player_setting_text_t *p_vals);
+
+ /** Returns the current songs' element attributes text ("Title"/"Album"/"Artist")
+ ** num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
+ */
+ bt_status_t (*get_element_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs);
+
+ /** Response to set player attribute request ("Shuffle"/"Repeat")
+ ** rsp_status: Status of setting the player attributes for the current media player
+ */
+ bt_status_t (*set_player_app_value_rsp)(btrc_status_t rsp_status);
+
+ /* Response to the register notification request (Play state change/track change/...).
+ ** event_id: Refers to the event_id this notification change corresponds too
+ ** type: Response type - interim/changed
+ ** p_params: Based on the event_id, this parameter should be populated
+ */
+ bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
+ btrc_notification_type_t type,
+ btrc_register_notification_t *p_param);
+
+ /* AVRCP 1.4 enhancements */
+
+ /**Send current volume setting to remote side. Support limited to SetAbsoluteVolume
+ ** This can be enhanced to support Relative Volume (AVRCP 1.0).
+ ** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN opposed to absolute volume level
+ ** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
+ */
+ bt_status_t (*set_volume)(uint8_t volume);
+
+ /** Closes the interface. */
+ void (*cleanup)( void );
+} btrc_interface_t;
+
+
+typedef void (* btrc_passthrough_rsp_callback) (int id, int key_state);
+
+typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
+
+/** BT-RC Controller callback structure. */
+typedef struct {
+ /** set to sizeof(BtRcCallbacks) */
+ size_t size;
+ btrc_passthrough_rsp_callback passthrough_rsp_cb;
+ btrc_connection_state_callback connection_state_cb;
+} btrc_ctrl_callbacks_t;
+
+void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data);
+
+BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr);
+
+void btc_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp);
+
+#endif /* __BTC_AVRC_H__ */
+++ /dev/null
-/******************************************************************************
- *
- * Copyright (C) 2009-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-
-/*****************************************************************************
- *
- * Filename: btif_av.c
- *
- * Description: Bluedroid AV implementation
- *
- *****************************************************************************/
-
-#include "bt_trace.h"
-#include <string.h>
-
-#include "bt_defs.h"
-#include "esp_bt_defs.h"
-#include "esp_a2dp_api.h"
-#include "allocator.h"
-
-#define LOG_TAG "bt_btif_av"
-
-#include "btif_av.h"
-#include "btif_util.h"
-#include "btif_profile_queue.h"
-#include "bta_api.h"
-#include "btif_media.h"
-#include "bta_av_api.h"
-#include "gki.h"
-#include "btu.h"
-#include "bt_utils.h"
-
-/*****************************************************************************
-** Constants & Macros
-******************************************************************************/
-#define BTIF_AV_SERVICE_NAME "Advanced Audio"
-
-#define BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS 2
-
-typedef enum {
- BTIF_AV_STATE_IDLE = 0x0,
- BTIF_AV_STATE_OPENING,
- BTIF_AV_STATE_OPENED,
- BTIF_AV_STATE_STARTED,
- BTIF_AV_STATE_CLOSING
-} btif_av_state_t;
-
-/* Should not need dedicated suspend state as actual actions are no
- different than open state. Suspend flags are needed however to prevent
- media task from trying to restart stream during remote suspend or while
- we are in the process of a local suspend */
-
-#define BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING 0x1
-#define BTIF_AV_FLAG_REMOTE_SUSPEND 0x2
-#define BTIF_AV_FLAG_PENDING_START 0x4
-#define BTIF_AV_FLAG_PENDING_STOP 0x8
-
-/*****************************************************************************
-** Local type definitions
-******************************************************************************/
-
-typedef struct {
- tBTA_AV_HNDL bta_handle;
- bt_bdaddr_t peer_bda;
- btif_sm_handle_t sm_handle;
- UINT8 flags;
- tBTA_AV_EDR edr;
- UINT8 peer_sep; /* sep type of peer device */
-} btif_av_cb_t;
-
-typedef struct {
- bt_bdaddr_t *target_bda;
- uint16_t uuid;
-} btif_av_connect_req_t;
-
-/*****************************************************************************
-** Static variables
-******************************************************************************/
-
-static esp_a2d_cb_t bt_av_sink_callback = NULL;
-
-static btif_av_cb_t btif_av_cb = {0};
-static TIMER_LIST_ENT tle_av_open_on_rc;
-
-// TODO: need protection against race
-#define BTIF_A2D_CB_TO_APP(_event, _param) do { \
- if (bt_av_sink_callback) { \
- bt_av_sink_callback(_event, _param); \
- } \
- } while (0)
-
-/* both interface and media task needs to be ready to alloc incoming request */
-#define CHECK_BTAV_INIT() if (btif_av_cb.sm_handle == NULL)\
-{\
- BTIF_TRACE_WARNING("%s: BTAV not initialized\n", __FUNCTION__);\
- return ESP_ERR_INVALID_STATE;\
-}\
-else\
-{\
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);\
-}
-
-/* Helper macro to avoid code duplication in the state machine handlers */
-#define CHECK_RC_EVENT(e, d) \
- case BTA_AV_RC_OPEN_EVT: \
- case BTA_AV_RC_CLOSE_EVT: \
- case BTA_AV_REMOTE_CMD_EVT: \
- case BTA_AV_VENDOR_CMD_EVT: \
- case BTA_AV_META_MSG_EVT: \
- case BTA_AV_RC_FEAT_EVT: \
- case BTA_AV_REMOTE_RSP_EVT: \
- { \
- btif_rc_handler(e, d);\
- }break; \
-
-static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *data);
-
-static const btif_sm_handler_t btif_av_state_handlers[] = {
- btif_av_state_idle_handler,
- btif_av_state_opening_handler,
- btif_av_state_opened_handler,
- btif_av_state_started_handler,
- btif_av_state_closing_handler
-};
-
-static void btif_av_event_free_data(btif_sm_event_t event, void *p_data);
-
-/*************************************************************************
-** Extern functions
-*************************************************************************/
-extern void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data);
-extern BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr);
-extern void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp);
-
-extern tBTA_AV_CO_FUNCTS bta_av_a2d_cos;
-/*****************************************************************************
-** Local helper functions
-******************************************************************************/
-
-const char *dump_av_sm_state_name(btif_av_state_t state)
-{
- switch (state) {
- CASE_RETURN_STR(BTIF_AV_STATE_IDLE)
- CASE_RETURN_STR(BTIF_AV_STATE_OPENING)
- CASE_RETURN_STR(BTIF_AV_STATE_OPENED)
- CASE_RETURN_STR(BTIF_AV_STATE_STARTED)
- CASE_RETURN_STR(BTIF_AV_STATE_CLOSING)
- default: return "UNKNOWN_STATE";
- }
-}
-
-const char *dump_av_sm_event_name(btif_av_sm_event_t event)
-{
- switch ((int)event) {
- CASE_RETURN_STR(BTA_AV_ENABLE_EVT)
- CASE_RETURN_STR(BTA_AV_REGISTER_EVT)
- CASE_RETURN_STR(BTA_AV_OPEN_EVT)
- CASE_RETURN_STR(BTA_AV_CLOSE_EVT)
- CASE_RETURN_STR(BTA_AV_START_EVT)
- CASE_RETURN_STR(BTA_AV_STOP_EVT)
- CASE_RETURN_STR(BTA_AV_PROTECT_REQ_EVT)
- CASE_RETURN_STR(BTA_AV_PROTECT_RSP_EVT)
- CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT)
- CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT)
- CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT)
- CASE_RETURN_STR(BTA_AV_REMOTE_RSP_EVT)
- CASE_RETURN_STR(BTA_AV_VENDOR_CMD_EVT)
- CASE_RETURN_STR(BTA_AV_VENDOR_RSP_EVT)
- CASE_RETURN_STR(BTA_AV_RECONFIG_EVT)
- CASE_RETURN_STR(BTA_AV_SUSPEND_EVT)
- CASE_RETURN_STR(BTA_AV_PENDING_EVT)
- CASE_RETURN_STR(BTA_AV_META_MSG_EVT)
- CASE_RETURN_STR(BTA_AV_REJECT_EVT)
- CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT)
- CASE_RETURN_STR(BTIF_SM_ENTER_EVT)
- CASE_RETURN_STR(BTIF_SM_EXIT_EVT)
- CASE_RETURN_STR(BTIF_AV_CONNECT_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_DISCONNECT_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_START_STREAM_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_STOP_STREAM_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_SUSPEND_STREAM_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_SINK_CONFIG_REQ_EVT)
- default: return "UNKNOWN_EVENT";
- }
-}
-
-/****************************************************************************
-** Local helper functions
-*****************************************************************************/
-/*******************************************************************************
-**
-** Function btif_initiate_av_open_tmr_hdlr
-**
-** Description Timer to trigger AV open if the remote headset establishes
-** RC connection w/o AV connection. The timer is needed to IOP
-** with headsets that do establish AV after RC connection.
-**
-** Returns void
-**
-*******************************************************************************/
-static void btif_initiate_av_open_tmr_hdlr(TIMER_LIST_ENT *tle)
-{
- BD_ADDR peer_addr;
- UNUSED(tle);
- btif_av_connect_req_t connect_req;
- UNUSED(tle);
- /* is there at least one RC connection - There should be */
- if (btif_rc_get_connected_peer(peer_addr)) {
- BTIF_TRACE_DEBUG("%s Issuing connect to the remote RC peer", __FUNCTION__);
- /* In case of AVRCP connection request, we will initiate SRC connection */
- connect_req.target_bda = (bt_bdaddr_t *)&peer_addr;
- connect_req.uuid = UUID_SERVCLASS_AUDIO_SOURCE;
- btif_sm_dispatch(btif_av_cb.sm_handle, BTIF_AV_CONNECT_REQ_EVT, (char *)&connect_req);
- } else {
- BTIF_TRACE_ERROR("%s No connected RC peers", __FUNCTION__);
- }
-}
-
-/*****************************************************************************
-** Static functions
-******************************************************************************/
-static void btif_report_connection_state(esp_a2d_connection_state_t state, bt_bdaddr_t *bd_addr, int disc_rsn)
-{
- esp_a2d_cb_param_t param;
- memset(¶m, 0, sizeof(esp_a2d_cb_param_t));
-
- param.conn_stat.state = state;
- if (bd_addr) {
- memcpy(param.conn_stat.remote_bda, bd_addr, sizeof(esp_bd_addr_t));
- }
- if (state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
- param.conn_stat.disc_rsn = (disc_rsn == 0) ? ESP_A2D_DISC_RSN_NORMAL :
- ESP_A2D_DISC_RSN_ABNORMAL;
- }
- BTIF_A2D_CB_TO_APP(ESP_A2D_CONNECTION_STATE_EVT, ¶m);
-}
-
-static void btif_report_audio_state(esp_a2d_audio_state_t state, bt_bdaddr_t *bd_addr)
-{
- esp_a2d_cb_param_t param;
- memset(¶m, 0, sizeof(esp_a2d_cb_param_t));
-
- param.audio_stat.state = state;
- if (bd_addr) {
- memcpy(param.audio_stat.remote_bda, bd_addr, sizeof(esp_bd_addr_t));
- }
- BTIF_A2D_CB_TO_APP(ESP_A2D_AUDIO_STATE_EVT, ¶m);
-}
-
-/*****************************************************************************
-**
-** Function btif_av_state_idle_handler
-**
-** Description State managing disconnected AV link
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data)
-{
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event) {
- case BTIF_SM_ENTER_EVT:
- /* clear the peer_bda */
- memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t));
- btif_av_cb.flags = 0;
- btif_av_cb.edr = 0;
- btif_a2dp_on_idle();
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_ENABLE_EVT:
- break;
-
- case BTA_AV_REGISTER_EVT:
- btif_av_cb.bta_handle = ((tBTA_AV *)p_data)->registr.hndl;
- break;
-
- case BTA_AV_PENDING_EVT:
- case BTIF_AV_CONNECT_REQ_EVT: {
- if (event == BTIF_AV_CONNECT_REQ_EVT) {
- memcpy(&btif_av_cb.peer_bda, ((btif_av_connect_req_t *)p_data)->target_bda,
- sizeof(bt_bdaddr_t));
- BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
- TRUE, BTA_SEC_AUTHENTICATE, ((btif_av_connect_req_t *)p_data)->uuid);
- } else if (event == BTA_AV_PENDING_EVT) {
- bdcpy(btif_av_cb.peer_bda.address, ((tBTA_AV *)p_data)->pend.bd_addr);
- BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
- TRUE, BTA_SEC_AUTHENTICATE, UUID_SERVCLASS_AUDIO_SOURCE);
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENING);
- } break;
-
- case BTA_AV_RC_OPEN_EVT:
- /* IOP_FIX: Jabra 620 only does RC open without AV open whenever it connects. So
- * as per the AV WP, an AVRC connection cannot exist without an AV connection. Therefore,
- * we initiate an AV connection if an RC_OPEN_EVT is received when we are in AV_CLOSED state.
- * We initiate the AV connection after a small 3s timeout to avoid any collisions from the
- * headsets, as some headsets initiate the AVRC connection first and then
- * immediately initiate the AV connection
- *
- * TODO: We may need to do this only on an AVRCP Play. FixMe
- */
-
- BTIF_TRACE_DEBUG("BTA_AV_RC_OPEN_EVT received w/o AV");
- memset(&tle_av_open_on_rc, 0, sizeof(tle_av_open_on_rc));
- tle_av_open_on_rc.param = (UINT32)btif_initiate_av_open_tmr_hdlr;
- btu_start_timer(&tle_av_open_on_rc, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS);
- btif_rc_handler(event, p_data);
- break;
-
- case BTA_AV_REMOTE_CMD_EVT:
- case BTA_AV_VENDOR_CMD_EVT:
- case BTA_AV_META_MSG_EVT:
- case BTA_AV_RC_FEAT_EVT:
- case BTA_AV_REMOTE_RSP_EVT:
- btif_rc_handler(event, (tBTA_AV *)p_data);
- break;
-
- case BTA_AV_RC_CLOSE_EVT:
- if (tle_av_open_on_rc.in_use) {
- BTIF_TRACE_DEBUG("BTA_AV_RC_CLOSE_EVT: Stopping AV timer.");
- btu_stop_timer(&tle_av_open_on_rc);
- }
- btif_rc_handler(event, p_data);
- break;
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
-
- return TRUE;
-}
-/*****************************************************************************
-**
-** Function btif_av_state_opening_handler
-**
-** Description Intermediate state managing events during establishment
-** of avdtp channel
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data)
-{
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event) {
- case BTIF_SM_ENTER_EVT:
- /* inform the application that we are entering connecting state */
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda), 0);
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_REJECT_EVT:
- BTIF_TRACE_DEBUG(" Received BTA_AV_REJECT_EVT \n");
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda), 0);
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
-
- case BTA_AV_OPEN_EVT: {
- tBTA_AV *p_bta_data = (tBTA_AV *)p_data;
- esp_a2d_connection_state_t state;
- btif_sm_state_t av_state;
- BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n", p_bta_data->open.status,
- p_bta_data->open.edr);
-
- if (p_bta_data->open.status == BTA_AV_SUCCESS) {
- state = ESP_A2D_CONNECTION_STATE_CONNECTED;
- av_state = BTIF_AV_STATE_OPENED;
- btif_av_cb.edr = p_bta_data->open.edr;
-
- btif_av_cb.peer_sep = p_bta_data->open.sep;
- btif_a2dp_set_peer_sep(p_bta_data->open.sep);
- } else {
- BTIF_TRACE_WARNING("BTA_AV_OPEN_EVT::FAILED status: %d\n",
- p_bta_data->open.status );
- state = ESP_A2D_CONNECTION_STATE_DISCONNECTED;
- av_state = BTIF_AV_STATE_IDLE;
- }
-
- /* inform the application of the event */
- btif_report_connection_state(state, &(btif_av_cb.peer_bda), 0);
- /* change state to open/idle based on the status */
- btif_sm_change_state(btif_av_cb.sm_handle, av_state);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
- /* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
- (p_bta_data->open.status == BTA_AV_SUCCESS));
- } else if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- /* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
- /* Bring up AVRCP connection too */
- BTA_AvOpenRc(btif_av_cb.bta_handle);
- }
- btif_queue_advance();
- } break;
-
- case BTIF_AV_SINK_CONFIG_REQ_EVT: {
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- esp_a2d_cb_param_t param;
- memcpy(param.audio_cfg.remote_bda, &btif_av_cb.peer_bda, sizeof(esp_bd_addr_t));
- memcpy(¶m.audio_cfg.mcc, p_data, sizeof(esp_a2d_mcc_t));
- BTIF_A2D_CB_TO_APP(ESP_A2D_AUDIO_CFG_EVT, ¶m);
- }
- } break;
-
- case BTIF_AV_CONNECT_REQ_EVT:
- // Check for device, if same device which moved to opening then ignore callback
- if (memcmp ((bt_bdaddr_t *)p_data, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0) {
- BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Connect Req\n", __func__);
- btif_queue_advance();
- break;
- } else {
- BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request\n", __func__);
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t *)p_data, 0);
- btif_queue_advance();
- break;
- }
-
- case BTA_AV_PENDING_EVT:
- // Check for device, if same device which moved to opening then ignore callback
- if (memcmp (((tBTA_AV *)p_data)->pend.bd_addr, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0) {
- BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Pending Req\n", __func__);
- break;
- } else {
- BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request\n", __func__);
- BTA_AvDisconnect(((tBTA_AV *)p_data)->pend.bd_addr);
- break;
- }
-
- CHECK_RC_EVENT(event, p_data);
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
- return TRUE;
-}
-
-
-/*****************************************************************************
-**
-** Function btif_av_state_closing_handler
-**
-** Description Intermediate state managing events during closing
-** of avdtp channel
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data)
-{
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event) {
- case BTIF_SM_ENTER_EVT:
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- btif_a2dp_set_rx_flush(TRUE);
- }
- break;
-
- case BTA_AV_STOP_EVT:
- case BTIF_AV_STOP_STREAM_REQ_EVT:
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- btif_a2dp_set_rx_flush(TRUE);
- }
-
- btif_a2dp_on_stopped(NULL);
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_CLOSE_EVT: {
- tBTA_AV_CLOSE *close = (tBTA_AV_CLOSE *)p_data;
- /* inform the application that we are disconnecting */
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda),
- close->disc_rsn);
-
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
- }
-
- /* Handle the RC_CLOSE event for the cleanup */
- case BTA_AV_RC_CLOSE_EVT:
- btif_rc_handler(event, (tBTA_AV *)p_data);
- break;
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
- }
- return TRUE;
-}
-
-
-/*****************************************************************************
-**
-** Function btif_av_state_opened_handler
-**
-** Description Handles AV events while AVDTP is in OPEN state
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
-{
- tBTA_AV *p_av = (tBTA_AV *)p_data;
-
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- if ( (event == BTA_AV_REMOTE_CMD_EVT) && (btif_av_cb.flags & BTIF_AV_FLAG_REMOTE_SUSPEND) &&
- (p_av->remote_cmd.rc_id == BTA_AV_RC_PLAY) ) {
- BTIF_TRACE_EVENT("%s: Resetting remote suspend flag on RC PLAY\n", __FUNCTION__);
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
- }
-
- switch (event) {
- case BTIF_SM_ENTER_EVT:
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_STOP;
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- break;
-
- case BTIF_SM_EXIT_EVT:
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- break;
-
- case BTIF_AV_START_STREAM_REQ_EVT:
- BTA_AvStart();
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
- break;
-
- case BTA_AV_START_EVT: {
- BTIF_TRACE_EVENT("BTA_AV_START_EVT status %d, suspending %d, init %d\n",
- p_av->start.status, p_av->start.suspending, p_av->start.initiator);
-
- if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE)) {
- return TRUE;
- }
-
- /* remain in open state if status failed */
- if (p_av->start.status != BTA_AV_SUCCESS) {
- return FALSE;
- }
-
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- btif_a2dp_set_rx_flush(FALSE); /* remove flush state, ready for streaming*/
- }
-
- /* change state to started, send acknowledgement if start is pending */
- if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
-
- /* pending start flag will be cleared when exit current state */
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED);
-
- } break;
-
- case BTIF_AV_DISCONNECT_REQ_EVT:
- BTA_AvClose(btif_av_cb.bta_handle);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- BTA_AvCloseRc(btif_av_cb.bta_handle);
- }
-
- /* inform the application that we are disconnecting */
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda), 0);
- break;
-
- case BTA_AV_CLOSE_EVT: {
- /* avdtp link is closed */
- btif_a2dp_on_stopped(NULL);
-
- tBTA_AV_CLOSE *close = (tBTA_AV_CLOSE *)p_data;
- /* inform the application that we are disconnected */
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda),
- close->disc_rsn);
-
- /* change state to idle, send acknowledgement if start is pending */
- if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
- /* pending start flag will be cleared when exit current state */
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
- }
-
- case BTA_AV_RECONFIG_EVT:
- if ((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) &&
- (p_av->reconfig.status == BTA_AV_SUCCESS)) {
- APPL_TRACE_WARNING("reconfig done BTA_AVstart()\n");
- BTA_AvStart();
- } else if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- }
- break;
-
- case BTIF_AV_CONNECT_REQ_EVT:
- if (memcmp ((bt_bdaddr_t *)p_data, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0) {
- BTIF_TRACE_DEBUG("%s: Ignore BTIF_AV_CONNECT_REQ_EVT for same device\n", __func__);
- } else {
- BTIF_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__);
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED,
- (bt_bdaddr_t *)p_data, ESP_A2D_DISC_RSN_NORMAL);
- }
- btif_queue_advance();
- break;
-
- CHECK_RC_EVENT(event, p_data);
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
- return TRUE;
-}
-
-/*****************************************************************************
-**
-** Function btif_av_state_started_handler
-**
-** Description Handles AV events while A2DP stream is started
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data)
-{
- tBTA_AV *p_av = (tBTA_AV *)p_data;
-
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event) {
- case BTIF_SM_ENTER_EVT:
-
- /* we are again in started state, clear any remote suspend flags */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
-
- btif_report_audio_state(ESP_A2D_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
-
- /* increase the a2dp consumer task priority temporarily when start
- ** audio playing, to avoid overflow the audio packet queue. */
- adjust_priority_a2dp(TRUE);
-
- break;
-
- case BTIF_SM_EXIT_EVT:
- /* restore the a2dp consumer task priority when stop audio playing. */
- adjust_priority_a2dp(FALSE);
-
- break;
-
- case BTIF_AV_START_STREAM_REQ_EVT:
- break;
-
- /* fixme -- use suspend = true always to work around issue with BTA AV */
- case BTIF_AV_STOP_STREAM_REQ_EVT:
- case BTIF_AV_SUSPEND_STREAM_REQ_EVT:
-
- /* set pending flag to ensure btif task is not trying to restart
- stream while suspend is in progress */
- btif_av_cb.flags |= BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
-
- /* if we were remotely suspended but suspend locally, local suspend
- always overrides */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
-
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- btif_a2dp_set_rx_flush(TRUE);
- btif_a2dp_on_stopped(NULL);
- }
-
- BTA_AvStop(TRUE);
- break;
-
- case BTIF_AV_DISCONNECT_REQ_EVT:
-
- /* request avdtp to close */
- BTA_AvClose(btif_av_cb.bta_handle);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- BTA_AvCloseRc(btif_av_cb.bta_handle);
- }
-
- /* inform the application that we are disconnecting */
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda), 0);
-
- /* wait in closing state until fully closed */
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_CLOSING);
- break;
-
- case BTA_AV_SUSPEND_EVT:
-
- BTIF_TRACE_EVENT("BTA_AV_SUSPEND_EVT status %d, init %d\n",
- p_av->suspend.status, p_av->suspend.initiator);
-
- /* a2dp suspended, stop media task until resumed */
- btif_a2dp_on_suspended(&p_av->suspend);
-
- /* if not successful, remain in current state */
- if (p_av->suspend.status != BTA_AV_SUCCESS) {
- btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
-
- return FALSE;
- }
-
- if (p_av->suspend.initiator != TRUE) {
- /* remote suspend, notify HAL and await audioflinger to
- suspend/stop stream */
-
- /* set remote suspend flag to block media task from restarting
- stream only if we did not already initiate a local suspend */
- if ((btif_av_cb.flags & BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING) == 0) {
- btif_av_cb.flags |= BTIF_AV_FLAG_REMOTE_SUSPEND;
- }
-
- btif_report_audio_state(ESP_A2D_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda));
- } else {
- btif_report_audio_state(ESP_A2D_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
- }
-
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
-
- /* suspend completed and state changed, clear pending status */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
- break;
-
- case BTA_AV_STOP_EVT:
-
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
- btif_a2dp_on_stopped(&p_av->suspend);
-
- btif_report_audio_state(ESP_A2D_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
-
- /* if stop was successful, change state to open */
- if (p_av->suspend.status == BTA_AV_SUCCESS) {
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
- }
-
- break;
-
- case BTA_AV_CLOSE_EVT: {
-
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
-
- /* avdtp link is closed */
- btif_a2dp_on_stopped(NULL);
-
- tBTA_AV_CLOSE *close = (tBTA_AV_CLOSE *)p_data;
- /* inform the application that we are disconnected */
- btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda),
- close->disc_rsn);
-
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
- }
-
- CHECK_RC_EVENT(event, p_data);
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
- return TRUE;
-}
-
-/*****************************************************************************
-** Local event handlers
-******************************************************************************/
-
-static void btif_av_handle_event(UINT16 event, char *p_param)
-{
- btif_sm_dispatch(btif_av_cb.sm_handle, event, (void *)p_param);
- btif_av_event_free_data(event, p_param);
-}
-
-void btif_av_event_deep_copy(UINT16 event, char *p_dest, char *p_src)
-{
- tBTA_AV *av_src = (tBTA_AV *)p_src;
- tBTA_AV *av_dest = (tBTA_AV *)p_dest;
-
- // First copy the structure
- memcpy(p_dest, p_src, sizeof(tBTA_AV));
-
- switch (event) {
- case BTA_AV_META_MSG_EVT:
- if (av_src->meta_msg.p_data && av_src->meta_msg.len) {
- av_dest->meta_msg.p_data = osi_calloc(av_src->meta_msg.len);
- assert(av_dest->meta_msg.p_data);
- memcpy(av_dest->meta_msg.p_data, av_src->meta_msg.p_data, av_src->meta_msg.len);
- }
-
- if (av_src->meta_msg.p_msg) {
- av_dest->meta_msg.p_msg = osi_calloc(sizeof(tAVRC_MSG));
- assert(av_dest->meta_msg.p_msg);
- memcpy(av_dest->meta_msg.p_msg, av_src->meta_msg.p_msg, sizeof(tAVRC_MSG));
-
- if (av_src->meta_msg.p_msg->vendor.p_vendor_data &&
- av_src->meta_msg.p_msg->vendor.vendor_len) {
- av_dest->meta_msg.p_msg->vendor.p_vendor_data = osi_calloc(
- av_src->meta_msg.p_msg->vendor.vendor_len);
- assert(av_dest->meta_msg.p_msg->vendor.p_vendor_data);
- memcpy(av_dest->meta_msg.p_msg->vendor.p_vendor_data,
- av_src->meta_msg.p_msg->vendor.p_vendor_data,
- av_src->meta_msg.p_msg->vendor.vendor_len);
- }
- }
- break;
-
- default:
- break;
- }
-}
-
-static void btif_av_event_free_data(btif_sm_event_t event, void *p_data)
-{
- switch (event) {
- case BTA_AV_META_MSG_EVT: {
- tBTA_AV *av = (tBTA_AV *)p_data;
- if (av->meta_msg.p_data) {
- osi_free(av->meta_msg.p_data);
- }
-
- if (av->meta_msg.p_msg) {
- if (av->meta_msg.p_msg->vendor.p_vendor_data) {
- osi_free(av->meta_msg.p_msg->vendor.p_vendor_data);
- }
- osi_free(av->meta_msg.p_msg);
- }
- }
- break;
-
- default:
- break;
- }
-}
-
-static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data)
-{
- btif_transfer_context(btif_av_handle_event, event,
- (char *)p_data, sizeof(tBTA_AV), btif_av_event_deep_copy);
-}
-
-static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
-{
- btif_sm_state_t state;
- UINT8 que_len;
- tA2D_STATUS a2d_status;
- tA2D_SBC_CIE sbc_cie;
- esp_a2d_mcc_t mcc;
-
- if (event == BTA_AV_MEDIA_DATA_EVT) { /* Switch to BTIF_MEDIA context */
- state = btif_sm_get_state(btif_av_cb.sm_handle);
- if ( (state == BTIF_AV_STATE_STARTED) || /* send SBC packets only in Started State */
- (state == BTIF_AV_STATE_OPENED) ) {
- que_len = btif_media_sink_enque_buf((BT_HDR *)p_data);
- BTIF_TRACE_DEBUG(" Packets in Que %d\n", que_len);
- } else {
- return;
- }
- }
-
- if (event == BTA_AV_MEDIA_SINK_CFG_EVT) {
- /* send a command to BT Media Task */
- btif_reset_decoder((UINT8 *)p_data);
-
- /* currently only supportes SBC */
- a2d_status = A2D_ParsSbcInfo(&sbc_cie, (UINT8 *)p_data, FALSE);
- if (a2d_status == A2D_SUCCESS) {
- mcc.type = ESP_A2D_MCT_SBC;
- memcpy(&mcc.cie, (uint8_t *)p_data + 3, ESP_A2D_CIE_LEN_SBC);
- /* Switch to BTIF context */
- btif_transfer_context(btif_av_handle_event, BTIF_AV_SINK_CONFIG_REQ_EVT,
- (char *)&mcc, sizeof(mcc), NULL);
- } else {
- APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status);
- }
- }
-}
-/*******************************************************************************
-**
-** Function btif_av_init
-**
-** Description Initializes btif AV if not already done
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-
-bt_status_t btif_av_init()
-{
- if (btif_av_cb.sm_handle == NULL) {
- if (!btif_a2dp_start_media_task()) {
- return BT_STATUS_FAIL;
- }
-
- /* Also initialize the AV state machine */
- btif_av_cb.sm_handle =
- btif_sm_init((const btif_sm_handler_t *)btif_av_state_handlers, BTIF_AV_STATE_IDLE);
-
- btif_enable_service(BTA_A2DP_SOURCE_SERVICE_ID);
-#if (BTA_AV_SINK_INCLUDED == TRUE)
- btif_enable_service(BTA_A2DP_SINK_SERVICE_ID);
-#endif
-
- btif_a2dp_on_init();
- }
-
- return BT_STATUS_SUCCESS;
-}
-
-/**
- *
- * Function register A2DP callback
- *
- * Description Initializes the AV interface for sink mode
- *
- * Returns bt_status_t
- *
- */
-#if 0
-esp_err_t esp_a2d_register_callback(esp_a2d_cb_t callback)
-{
- // TODO: need protection against race
- bt_av_sink_callback = callback;
- return ESP_OK;
-}
-#endif /* #if 0 */
-/*******************************************************************************
-**
-** Function init_sink
-**
-** Description Initializes the AV interface for sink mode
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-#if 0
-esp_err_t esp_a2d_sink_init(void)
-{
- BTIF_TRACE_EVENT("%s()\n", __func__);
-
- bt_status_t status = btif_av_init();
-
- return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
-}
-#endif /* #endif */
-/*******************************************************************************
-**
-** Function connect
-**
-** Description Establishes the AV signalling channel with the remote headset
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-
-static bt_status_t connect_int(bt_bdaddr_t *bd_addr, uint16_t uuid)
-{
- btif_av_connect_req_t connect_req;
- connect_req.target_bda = bd_addr;
- connect_req.uuid = uuid;
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- btif_sm_dispatch(btif_av_cb.sm_handle, BTIF_AV_CONNECT_REQ_EVT, (char *)&connect_req);
-
- return BT_STATUS_SUCCESS;
-}
-
-#if 0
-esp_err_t esp_a2d_sink_connect(esp_bd_addr_t remote_bda)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- CHECK_BTAV_INIT();
-
- bt_status_t stat;
- bt_bdaddr_t bd_addr;
- memcpy(&bd_addr, remote_bda, sizeof(bt_bdaddr_t));
-
- stat = btif_queue_connect(UUID_SERVCLASS_AUDIO_SINK, &bd_addr, connect_int);
- return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
-}
-
-esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda)
-{
- bt_status_t stat;
- bt_bdaddr_t bd_addr;
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- CHECK_BTAV_INIT();
- memcpy(&bd_addr, remote_bda, sizeof(bt_bdaddr_t));
- /* Switch to BTIF context */
- stat = btif_transfer_context(btif_av_handle_event, BTIF_AV_DISCONNECT_REQ_EVT,
- (char *)(&bd_addr), sizeof(bt_bdaddr_t), NULL);
- return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
-}
-#endif /* #if 0 */
-/*******************************************************************************
-**
-** Function cleanup
-**
-** Description Shuts down the AV interface and does the cleanup
-**
-** Returns None
-**
-*******************************************************************************/
-static void cleanup(void)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- btif_a2dp_stop_media_task();
-
- btif_disable_service(BTA_A2DP_SOURCE_SERVICE_ID);
-#if (BTA_AV_SINK_INCLUDED == TRUE)
- btif_disable_service(BTA_A2DP_SINK_SERVICE_ID);
-#endif
-
- /* Also shut down the AV state machine */
- btif_sm_shutdown(btif_av_cb.sm_handle);
- btif_av_cb.sm_handle = NULL;
-}
-
-#if 0
-void esp_a2d_sink_deinit(void)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- if (bt_av_sink_callback) {
- bt_av_sink_callback = NULL;
- cleanup();
- }
-}
-#endif /* #if 0 */
-/*******************************************************************************
-**
-** Function btif_av_get_sm_handle
-**
-** Description Fetches current av SM handle
-**
-** Returns None
-**
-*******************************************************************************/
-
-btif_sm_handle_t btif_av_get_sm_handle(void)
-{
- return btif_av_cb.sm_handle;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_stream_ready
-**
-** Description Checks whether AV is ready for starting a stream
-**
-** Returns None
-**
-*******************************************************************************/
-
-BOOLEAN btif_av_stream_ready(void)
-{
- btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
-
- BTIF_TRACE_DEBUG("btif_av_stream_ready : sm hdl %d, state %d, flags %x\n",
- (int)btif_av_cb.sm_handle, state, btif_av_cb.flags);
-
- /* also make sure main adapter is enabled */
- if (btif_is_enabled() == 0) {
- BTIF_TRACE_EVENT("main adapter not enabled");
- return FALSE;
- }
-
- /* check if we are remotely suspended or stop is pending */
- if (btif_av_cb.flags & (BTIF_AV_FLAG_REMOTE_SUSPEND | BTIF_AV_FLAG_PENDING_STOP)) {
- return FALSE;
- }
-
- return (state == BTIF_AV_STATE_OPENED);
-}
-
-/*******************************************************************************
-**
-** Function btif_av_stream_started_ready
-**
-** Description Checks whether AV ready for media start in streaming state
-**
-** Returns None
-**
-*******************************************************************************/
-
-BOOLEAN btif_av_stream_started_ready(void)
-{
- btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
-
- BTIF_TRACE_DEBUG("btif_av_stream_started : sm hdl %d, state %d, flags %x\n",
- (int)btif_av_cb.sm_handle, state, btif_av_cb.flags);
-
- /* disallow media task to start if we have pending actions */
- if (btif_av_cb.flags & (BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING | BTIF_AV_FLAG_REMOTE_SUSPEND
- | BTIF_AV_FLAG_PENDING_STOP)) {
- return FALSE;
- }
-
- return (state == BTIF_AV_STATE_STARTED);
-}
-
-/*******************************************************************************
-**
-** Function btif_dispatch_sm_event
-**
-** Description Send event to AV statemachine
-**
-** Returns None
-**
-*******************************************************************************/
-
-/* used to pass events to AV statemachine from other tasks */
-void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len)
-{
- /* Switch to BTIF context */
- btif_transfer_context(btif_av_handle_event, event,
- (char *)p_data, len, NULL);
-}
-
-/*******************************************************************************
-**
-** Function btif_av_execute_service
-**
-** Description Initializes/Shuts down the service
-**
-** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
-**
-*******************************************************************************/
-bt_status_t btif_av_execute_service(BOOLEAN b_enable)
-{
- if (b_enable) {
- /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not
- * handle this request in order to allow incoming connections to succeed.
- * We need to put this back once support for this is added */
-
- /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not
- * auto-suspend av streaming on AG events(SCO or Call). The suspend shall
- * be initiated by the app/audioflinger layers */
- BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_NO_SCO_SSPD)
- // | BTA_AV_FEAT_RCTG | BTA_AV_FEAT_METADATA | BTA_AV_FEAT_VENDOR
- | BTA_AV_FEAT_RCCT | BTA_AV_FEAT_ADV_CTRL,
- bte_av_callback);
- BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos);
- } else {
- BTA_AvDeregister(btif_av_cb.bta_handle);
- BTA_AvDisable();
- }
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_sink_execute_service
-**
-** Description Initializes/Shuts down the service
-**
-** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
-**
-*******************************************************************************/
-bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable)
-{
-#if (BTA_AV_SINK_INCLUDED == TRUE)
- BTA_AvEnable_Sink(b_enable);
-#endif
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_is_connected
-**
-** Description Checks if av has a connected sink
-**
-** Returns BOOLEAN
-**
-*******************************************************************************/
-BOOLEAN btif_av_is_connected(void)
-{
- btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
- return ((state == BTIF_AV_STATE_OPENED) || (state == BTIF_AV_STATE_STARTED));
-}
-
-/*******************************************************************************
-**
-** Function btif_av_is_peer_edr
-**
-** Description Check if the connected a2dp device supports
-** EDR or not. Only when connected this function
-** will accurately provide a true capability of
-** remote peer. If not connected it will always be false.
-**
-** Returns TRUE if remote device is capable of EDR
-**
-*******************************************************************************/
-BOOLEAN btif_av_is_peer_edr(void)
-{
- ASSERTC(btif_av_is_connected(), "No active a2dp connection\n", 0);
-
- if (btif_av_cb.edr) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-/******************************************************************************
-**
-** Function btif_av_clear_remote_suspend_flag
-**
-** Description Clears btif_av_cd.flags if BTIF_AV_FLAG_REMOTE_SUSPEND is set
-**
-** Returns void
-******************************************************************************/
-void btif_av_clear_remote_suspend_flag(void)
-{
- BTIF_TRACE_DEBUG("%s: flag :%x\n", __func__, btif_av_cb.flags);
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
-}
+++ /dev/null
-/******************************************************************************
- *
- * Copyright (C) 2014 The Android Open Source Project
- * Copyright (C) 2009-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-/************************************************************************************
- *
- * Filename: btif_core.c
- *
- * Description: Contains core functionality related to interfacing between
- * Bluetooth HAL and BTE core stack.
- *
- ***********************************************************************************/
-
-#include <ctype.h>
-// #include <cutils/properties.h>
-// #include <dirent.h>
-// #include <fcntl.h>
-// #include <hardware/bluetooth.h>
-#include <stdlib.h>
-#include <string.h>
-// #include <sys/stat.h>
-// #include <sys/types.h>
-
-#define LOG_TAG "bt_btif_core"
-// #include "btcore/include/bdaddr.h"
-
-#include "bdaddr.h"
-// #include "bt_utils.h"
-#include "bta_api.h"
-#include "bte.h"
-#include "btif_api.h"
-// #include "btif_av.h"
-// #include "btif_config.h"
-// #include "btif_pan.h"
-// #include "btif_profile_queue.h"
-// #include "btif_config.h"
-// #include "btif_sock.h"
-// #include "btif_storage.h"
-#include "btif_util.h"
-#include "btu.h"
-#include "controller.h"
-#include "fixed_queue.h"
-#include "future.h"
-#include "gki.h"
-#include "osi.h"
-// #include "osi/include/log.h"
-#include "stack_manager.h"
-#include "thread.h"
-#include "btif_common.h"
-#include "btif_dm.h"
-/************************************************************************************
-** Constants & Macros
-************************************************************************************/
-
-/************************************************************************************
-** Local type definitions
-************************************************************************************/
-
-/************************************************************************************
-** Static variables
-************************************************************************************/
-
-static tBTA_SERVICE_MASK btif_enabled_services = 0;
-
-static fixed_queue_t *btif_msg_queue = NULL;
-static xTaskHandle xBtifTaskHandle = NULL;
-
-/************************************************************************************
-** Static functions
-************************************************************************************/
-
-/* sends message to btif task */
-static void btif_sendmsg(void *p_msg);
-static void btif_thread_post(uint32_t sig);
-/************************************************************************************
-** Externs
-************************************************************************************/
-static fixed_queue_t *xBtifQueue = NULL;
-
-/** TODO: Move these to _common.h */
-void bte_main_boot_entry(void *);
-void bte_main_disable(void);
-void bte_main_shutdown(void);
-void btif_dm_execute_service_request(UINT16 event, char *p_param);
-
-/*******************************************************************************
-**
-** Function btif_context_switched
-**
-** Description Callback used to execute transferred context callback
-**
-** p_msg : message to be executed in btif context
-**
-** Returns void
-**
-*******************************************************************************/
-
-static void btif_context_switched(void *p_msg)
-{
-
- BTIF_TRACE_VERBOSE("btif_context_switched");
-
- tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
-
- /* each callback knows how to parse the data */
- if (p->p_cb) {
- p->p_cb(p->event, p->p_param);
- }
-}
-
-
-/*******************************************************************************
-**
-** Function btif_transfer_context
-**
-** Description This function switches context to btif task
-**
-** p_cback : callback used to process message in btif context
-** event : event id of message
-** p_params : parameter area passed to callback (copied)
-** param_len : length of parameter area
-** p_copy_cback : If set this function will be invoked for deep copy
-**
-** Returns void
-**
-*******************************************************************************/
-
-bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char *p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback)
-{
- tBTIF_CONTEXT_SWITCH_CBACK *p_msg;
-
- BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
-
- /* allocate and send message that will be executed in btif context */
- if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) {
- p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
- p_msg->p_cb = p_cback;
-
- p_msg->event = event; /* callback event */
-
- /* check if caller has provided a copy callback to do the deep copy */
- if (p_copy_cback) {
- p_copy_cback(event, p_msg->p_param, p_params);
- } else if (p_params) {
- memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
- }
-
- btif_sendmsg(p_msg);
- return BT_STATUS_SUCCESS;
- } else {
- /* let caller deal with a failed allocation */
- return BT_STATUS_NOMEM;
- }
-}
-
-int btif_is_enabled(void)
-{
- return (stack_manager_is_stack_running());
-}
-
-void btif_init_ok(void)
-{
- BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
- future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
-}
-
-/*******************************************************************************
-**
-** Function btif_enable_bluetooth_evt
-**
-** Description Event indicating bluetooth enable is completed
-** Notifies HAL user with updated adapter state
-**
-** Returns void
-**
-*******************************************************************************/
-
-void btif_enable_bluetooth_evt(tBTA_STATUS status)
-{
- if (status == BTA_SUCCESS) {
- future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
- } else {
- future_ready(stack_manager_get_hack_future(), FUTURE_FAIL);
- }
-}
-
-/*******************************************************************************
-**
-** Function btif_disable_bluetooth_evt
-**
-** Description Event notifying BT disable is now complete.
-** Terminates main stack tasks and notifies HAL
-** user with updated BT state.
-**
-** Returns void
-**
-*******************************************************************************/
-
-void btif_disable_bluetooth_evt(void)
-{
- BTIF_TRACE_DEBUG("%s", __FUNCTION__);
-
- /* callback to HAL */
- future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
-}
-
-/*******************************************************************************
-**
-** Function btif_task
-**
-** Description BTIF task handler managing all messages being passed
-** Bluetooth HAL and BTA.
-**
-** Returns void
-**
-*******************************************************************************/
-static void bt_jni_msg_ready(fixed_queue_t *queue)
-{
- BT_HDR *p_msg;
- while (!fixed_queue_is_empty(queue)) {
- p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
- BTIF_TRACE_VERBOSE("btif task fetched event %x", p_msg->event);
- switch (p_msg->event) {
- case BT_EVT_CONTEXT_SWITCH_EVT:
- btif_context_switched(p_msg);
- break;
- default:
- BTIF_TRACE_ERROR("unhandled btif event (%d)", p_msg->event & BT_EVT_MASK); break;
- }
- GKI_freebuf(p_msg);
- }
-}
-
-/*******************************************************************************
-**
-** Function btif_sendmsg
-**
-** Description Sends msg to BTIF task
-**
-** Returns void
-**
-*******************************************************************************/
-
-void btif_sendmsg(void *p_msg)
-{
- fixed_queue_enqueue(btif_msg_queue, p_msg);
- btif_thread_post(SIG_BTIF_WORK);
-}
-
-static void btif_thread_post(uint32_t sig)
-{
- BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
- if (evt == NULL) {
- return;
- }
-
- evt->sig = sig;
- evt->par = 0;
-
- if (xQueueSend(xBtifQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
- ets_printf("xBtifQueue failed\n");
- }
-}
-
-/*****************************************************************************
-**
-** Function btif_task_thread_handler
-**
-** Description Process BTif Task Thread.
-******************************************************************************/
-void btif_task_thread_handler(void *arg)
-{
- BtTaskEvt_t *e;
- for (;;) {
- if (pdTRUE == xQueueReceive(xBtifQueue, &e, (portTickType)portMAX_DELAY)) {
- if (e->sig == SIG_BTIF_WORK) {
- fixed_queue_process(btif_msg_queue);
- }
- osi_free(e);
- }
- }
-}
-
-/*******************************************************************************
-**
-** Function btif_init_bluetooth
-**
-** Description Creates BTIF task and prepares BT scheduler for startup
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-bt_status_t btif_init_bluetooth(void)
-{
- bte_main_boot_entry(btif_init_ok);
-
- btif_msg_queue = fixed_queue_new(SIZE_MAX);
- if (btif_msg_queue == NULL) {
- goto error_exit;
- }
- xBtifQueue = xQueueCreate(60, sizeof(void *));
- xTaskCreatePinnedToCore(btif_task_thread_handler, "BtifT", 2048+1024, NULL, configMAX_PRIORITIES - 1, &xBtifTaskHandle, 0);
- fixed_queue_register_dequeue(btif_msg_queue, bt_jni_msg_ready);
-
- return BT_STATUS_SUCCESS;
-
-error_exit:;
- btif_shutdown_bluetooth();
-
- return BT_STATUS_FAIL;
-}
-
-/*******************************************************************************
-**
-** Function btif_enable_bluetooth
-**
-** Description Inititates shutdown of Bluetooth system.
-** Any active links will be dropped and device entering
-** non connectable/discoverable mode
-**
-** Returns void
-**
-*******************************************************************************/
-bt_status_t btif_enable_bluetooth(void)
-{
- BTIF_TRACE_DEBUG("BTIF ENABLE BLUETOOTH");
-
- BTA_EnableBluetooth(bte_dm_evt);
-
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function btif_disable_bluetooth
-**
-** Description Inititates shutdown of Bluetooth system.
-** Any active links will be dropped and device entering
-** non connectable/discoverable mode
-**
-** Returns void
-**
-*******************************************************************************/
-bt_status_t btif_disable_bluetooth(void)
-{
- BTIF_TRACE_DEBUG("BTIF DISABLE BLUETOOTH");
-
- // btif_dm_on_disable();
- /* cleanup rfcomm & l2cap api */
- // btif_sock_cleanup();
- // btif_pan_cleanup();
- BTA_DisableBluetooth();
-
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function btif_shutdown_bluetooth
-**
-** Description Finalizes BT scheduler shutdown and terminates BTIF
-** task.
-**
-** Returns void
-**
-*******************************************************************************/
-
-bt_status_t btif_shutdown_bluetooth(void)
-{
- BTIF_TRACE_DEBUG("%s", __FUNCTION__);
-
- fixed_queue_unregister_dequeue(btif_msg_queue);
- fixed_queue_free(btif_msg_queue, NULL);
- btif_msg_queue = NULL;
-
- vTaskDelete(xBtifTaskHandle);
- xBtifTaskHandle = NULL;
-
- vQueueDelete(xBtifQueue);
- xBtifQueue = NULL;
-
- bte_main_shutdown();
-
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function btif_get_enabled_services_mask
-**
-** Description Fetches currently enabled services
-**
-** Returns tBTA_SERVICE_MASK
-**
-*******************************************************************************/
-
-tBTA_SERVICE_MASK btif_get_enabled_services_mask(void)
-{
- return btif_enabled_services;
-}
-
-/*******************************************************************************
-**
-** Function btif_enable_service
-**
-** Description Enables the service 'service_ID' to the service_mask.
-** Upon BT enable, BTIF core shall invoke the BTA APIs to
-** enable the profiles
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id)
-{
- tBTA_SERVICE_ID *p_id = &service_id;
-
- /* If BT is enabled, we need to switch to BTIF context and trigger the
- * enable for that profile
- *
- * Otherwise, we just set the flag. On BT_Enable, the DM will trigger
- * enable for the profiles that have been enabled */
-
- btif_enabled_services |= (1 << service_id);
-
- BTIF_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btif_enabled_services);
-
- if (btif_is_enabled()) {
- btif_transfer_context(btif_dm_execute_service_request,
- BTIF_DM_ENABLE_SERVICE,
- (char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
- }
-
- return BT_STATUS_SUCCESS;
-}
-/*******************************************************************************
-**
-** Function btif_disable_service
-**
-** Description Disables the service 'service_ID' to the service_mask.
-** Upon BT disable, BTIF core shall invoke the BTA APIs to
-** disable the profiles
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id)
-{
- tBTA_SERVICE_ID *p_id = &service_id;
-
- /* If BT is enabled, we need to switch to BTIF context and trigger the
- * disable for that profile so that the appropriate uuid_property_changed will
- * be triggerred. Otherwise, we just need to clear the service_id in the mask
- */
-
- btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id));
-
- BTIF_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services);
-
- if (btif_is_enabled()) {
- btif_transfer_context(btif_dm_execute_service_request,
- BTIF_DM_DISABLE_SERVICE,
- (char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
- }
-
- return BT_STATUS_SUCCESS;
-}
+++ /dev/null
-/******************************************************************************
- *
- * Copyright (C) 2009-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-/************************************************************************************
- *
- * Filename: btif_dm.c
- *
- * Description: Contains Device Management (DM) related functionality
- *
- *
- ***********************************************************************************/
-
-#define LOG_TAG "bt_btif_dm"
-
-// #include <assert.h>
-// #include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-// #include <sys/types.h>
-// #include <unistd.h>
-
-// #include <hardware/bluetooth.h>
-
-// #include <cutils/properties.h>
-#include "gki.h"
-#include "btu.h"
-// #include "btcore/include/bdaddr.h"
-#include "bta_api.h"
-#include "btif_api.h"
-#include "btif_util.h"
-#include "btif_dm.h"
-#include "btif_storage.h"
-// #include "btif_hh.h"
-// #include "btif_config.h"
-// #include "btif_sdp.h"
-// #include "bta_gatt_api.h"
-// #include "device/include/interop.h"
-// #include "include/stack_config.h"
-// #include "osi/include/log.h"
-#include "allocator.h"
-#include "btm_int.h"
-#include "bt_defs.h"
-#include "future.h"
-#include "stack_manager.h"
-
-/******************************************************************************
-** Constants & Macros
-******************************************************************************/
-#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
-
-/************************************************************************************
-** Static variables
-************************************************************************************/
-/******************************************************************************
-** Static functions
-******************************************************************************/
-/******************************************************************************
-** Externs
-******************************************************************************/
-// extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
-extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
-extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
-/******************************************************************************
-** Functions
-******************************************************************************/
-
-static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
-{
- tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC *)dst;
- tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC *)src;
-
- if (!src_dm_sec) {
- return;
- }
-
- assert(dst_dm_sec);
- memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
-
- if (event == BTA_DM_BLE_KEY_EVT) {
- dst_dm_sec->ble_key.p_key_value = osi_malloc(sizeof(tBTM_LE_KEY_VALUE));
- assert(src_dm_sec->ble_key.p_key_value);
- assert(dst_dm_sec->ble_key.p_key_value);
- memcpy(dst_dm_sec->ble_key.p_key_value, src_dm_sec->ble_key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
- }
-}
-
-static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec)
-{
- if (event == BTA_DM_BLE_KEY_EVT) {
- osi_free(dm_sec->ble_key.p_key_value);
- }
-}
-
-bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
- BOOLEAN b_enable)
-{
- BTIF_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
- /* Check the service_ID and invoke the profile's BT state changed API */
- switch (service_id) {
- case BTA_A2DP_SOURCE_SERVICE_ID:
- btif_av_execute_service(b_enable);
- break;
- case BTA_A2DP_SINK_SERVICE_ID:
- btif_av_sink_execute_service(b_enable);
- break;
- default:
- BTIF_TRACE_ERROR("%s: Unknown service being enabled\n", __FUNCTION__);
- return BT_STATUS_FAIL;
- }
- return BT_STATUS_SUCCESS;
-}
-
-void btif_dm_execute_service_request(UINT16 event, char *p_param)
-{
- BOOLEAN b_enable = FALSE;
- if (event == BTIF_DM_ENABLE_SERVICE) {
- b_enable = TRUE;
- }
-
- btif_in_execute_service_request(*((tBTA_SERVICE_ID *)p_param), b_enable);
-}
-
-/*******************************************************************************
-**
-** Function btif_dm_auth_cmpl_evt
-**
-** Description Executes authentication complete event in btif context
-**
-** Returns void
-**
-*******************************************************************************/
-// static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
-void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
-{
- /* Save link key, if not temporary */
- bt_bdaddr_t bd_addr;
- bt_status_t status;
- BTIF_TRACE_EVENT("%s: bond state success %d, present %d, type%d\n", __func__, p_auth_cmpl->success,
- p_auth_cmpl->key_present, p_auth_cmpl->key_type);
-
- bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
- if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
- {
- #if 0
- if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
- (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
- (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) ||
- (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB_P_256)
- )
- #endif
- if (1)
- {
- bt_status_t ret;
- BTIF_TRACE_EVENT("%s: Storing link key. key_type=0x%x",
- __FUNCTION__, p_auth_cmpl->key_type);
- ret = btif_storage_add_bonded_device(&bd_addr,
- p_auth_cmpl->key, p_auth_cmpl->key_type,
- 16);
- ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
- }
- else
- {
- BTIF_TRACE_EVENT("%s: Temporary key. Not storing. key_type=0x%x",
- __FUNCTION__, p_auth_cmpl->key_type);
- }
- }
-
- // Skip SDP for certain HID Devices
- if (p_auth_cmpl->success)
- {
- }
- else
- {
- // Map the HCI fail reason to bt status
- switch(p_auth_cmpl->fail_reason)
- {
- case HCI_ERR_PAGE_TIMEOUT:
- BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying () ...", __FUNCTION__);
- return;
- /* Fall-through */
- case HCI_ERR_CONNECTION_TOUT:
- status = BT_STATUS_RMT_DEV_DOWN;
- break;
-
- case HCI_ERR_PAIRING_NOT_ALLOWED:
- status = BT_STATUS_AUTH_REJECTED;
- break;
-
- case HCI_ERR_LMP_RESPONSE_TIMEOUT:
- status = BT_STATUS_AUTH_FAILURE;
- break;
-
- /* map the auth failure codes, so we can retry pairing if necessary */
- case HCI_ERR_AUTH_FAILURE:
- case HCI_ERR_KEY_MISSING:
- btif_storage_remove_bonded_device(&bd_addr);
- case HCI_ERR_HOST_REJECT_SECURITY:
- case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
- case HCI_ERR_UNIT_KEY_USED:
- case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
- case HCI_ERR_INSUFFCIENT_SECURITY:
- case HCI_ERR_PEER_USER:
- case HCI_ERR_UNSPECIFIED:
- BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d",
- __FUNCTION__, p_auth_cmpl->fail_reason);
- /* if autopair attempts are more than 1, or not attempted */
- status = BT_STATUS_AUTH_FAILURE;
- break;
- default:
- status = BT_STATUS_FAIL;
- }
- }
- (void) status;
-}
-
-/*******************************************************************************
-**
-** Function btif_dm_upstreams_cback
-**
-** Description Executes UPSTREAMS events in btif context
-**
-** Returns void
-**
-*******************************************************************************/
-static void btif_dm_upstreams_evt(UINT16 event, char *p_param)
-{
- tBTA_DM_SEC *p_data = (tBTA_DM_SEC *)p_param;
- tBTA_SERVICE_MASK service_mask;
- uint32_t i;
- BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %d\n", event);
-
- switch (event) {
- case BTA_DM_ENABLE_EVT:
- /* for each of the enabled services in the mask, trigger the profile
- * enable */
- service_mask = btif_get_enabled_services_mask();
- for (i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
- if (service_mask &
- (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
- btif_in_execute_service_request(i, TRUE);
- }
- }
- btif_enable_bluetooth_evt(p_data->enable.status);
- btif_storage_load_bonded_devices();
- break;
- case BTA_DM_DISABLE_EVT:
- /* for each of the enabled services in the mask, trigger the profile
- * disable */
- service_mask = btif_get_enabled_services_mask();
- for (i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
- if (service_mask &
- (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
- btif_in_execute_service_request(i, FALSE);
- }
- }
- btif_disable_bluetooth_evt();
- break;
- case BTA_DM_PIN_REQ_EVT:
- break;
- case BTA_DM_AUTH_CMPL_EVT:
- btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
- break;
- case BTA_DM_BOND_CANCEL_CMPL_EVT:
- case BTA_DM_SP_CFM_REQ_EVT:
- case BTA_DM_SP_KEY_NOTIF_EVT:
-
- case BTA_DM_DEV_UNPAIRED_EVT:
- case BTA_DM_BUSY_LEVEL_EVT:
- case BTA_DM_LINK_UP_EVT:
- case BTA_DM_LINK_DOWN_EVT:
- case BTA_DM_HW_ERROR_EVT:
-
-#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
- case BTA_DM_BLE_KEY_EVT:
- case BTA_DM_BLE_SEC_REQ_EVT:
- case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
- case BTA_DM_BLE_PASSKEY_REQ_EVT:
- case BTA_DM_BLE_NC_REQ_EVT:
- case BTA_DM_BLE_OOB_REQ_EVT:
- case BTA_DM_BLE_LOCAL_IR_EVT:
- case BTA_DM_BLE_LOCAL_ER_EVT:
- case BTA_DM_BLE_AUTH_CMPL_EVT:
- case BTA_DM_LE_FEATURES_READ:
- case BTA_DM_ENER_INFO_READ:
-#endif
-
- case BTA_DM_AUTHORIZE_EVT:
- case BTA_DM_SIG_STRENGTH_EVT:
- case BTA_DM_SP_RMT_OOB_EVT:
- case BTA_DM_SP_KEYPRESS_EVT:
- case BTA_DM_ROLE_CHG_EVT:
-
- default:
- BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)\n", event );
- break;
- }
-
- btif_dm_data_free(event, p_data);
-}
-
-/*******************************************************************************
-**
-** Function bte_dm_evt
-**
-** Description Switches context from BTE to BTIF for all DM events
-**
-** Returns void
-**
-*******************************************************************************/
-
-void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
-{
- /* switch context to btif task context (copy full union size for convenience) */
- bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
- (void *)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
-
- /* catch any failed context transfers */
- ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status);
-}
#include "thread.h"
#include "bt_defs.h"
-#include "btif_av.h"
+#include "btc_av.h"
#include "btif_sm.h"
#include "btif_util.h"
#if (BTA_AV_SINK_INCLUDED == TRUE)
{
memset(&btif_media_cb, 0, sizeof(btif_media_cb));
LOG_INFO("media thread init\n");
- btif_media_cb.av_sm_hdl = btif_av_get_sm_handle();
+ btif_media_cb.av_sm_hdl = btc_av_get_sm_handle();
raise_priority_a2dp(TASK_HIGH_MEDIA);
media_task_running = MEDIA_TASK_STATE_ON;
}
+++ /dev/null
-/******************************************************************************
- *
- * Copyright (C) 2009-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-/*******************************************************************************
- *
- * Filename: btif_profile_queue.c
- *
- * Description: Bluetooth remote device connection queuing implementation.
- *
- ******************************************************************************/
-
-// #include <assert.h>
-#include "bt_trace.h"
-#include <string.h>
-// #include <hardware/bluetooth.h>
-#include "bt_defs.h"
-#include <string.h>
-
-#define LOG_TAG "bt_btif_queue"
-#include "btif_common.h"
-#include "btif_profile_queue.h"
-#include "gki.h"
-#include "list.h"
-#include "allocator.h"
-#include "stack_manager.h"
-
-/*******************************************************************************
-** Local type definitions
-*******************************************************************************/
-
-typedef enum {
- BTIF_QUEUE_CONNECT_EVT,
- BTIF_QUEUE_ADVANCE_EVT,
-} btif_queue_event_t;
-
-typedef struct {
- bt_bdaddr_t bda;
- uint16_t uuid;
- bool busy;
- btif_connect_cb_t connect_cb;
-} connect_node_t;
-
-/*******************************************************************************
-** Static variables
-*******************************************************************************/
-
-static list_t *connect_queue;
-
-static const size_t MAX_REASONABLE_REQUESTS = 10;
-
-/*******************************************************************************
-** Queue helper functions
-*******************************************************************************/
-
-static void queue_int_add(connect_node_t *p_param)
-{
- if (!connect_queue) {
- connect_queue = list_new(osi_free_func);
- assert(connect_queue != NULL);
- }
-
- // Sanity check to make sure we're not leaking connection requests
- assert(list_length(connect_queue) < MAX_REASONABLE_REQUESTS);
-
- for (const list_node_t *node = list_begin(connect_queue); node != list_end(connect_queue); node = list_next(node)) {
- if (((connect_node_t *)list_node(node))->uuid == p_param->uuid) {
- LOG_INFO("%s dropping duplicate connect request for uuid: %04x", __func__, p_param->uuid);
- return;
- }
- }
-
- connect_node_t *p_node = osi_malloc(sizeof(connect_node_t));
- assert(p_node != NULL);
- memcpy(p_node, p_param, sizeof(connect_node_t));
- list_append(connect_queue, p_node);
-}
-
-static void queue_int_advance()
-{
- if (connect_queue && !list_is_empty(connect_queue)) {
- list_remove(connect_queue, list_front(connect_queue));
- }
-}
-
-static void queue_int_handle_evt(UINT16 event, char *p_param)
-{
- switch (event) {
- case BTIF_QUEUE_CONNECT_EVT:
- queue_int_add((connect_node_t *)p_param);
- break;
-
- case BTIF_QUEUE_ADVANCE_EVT:
- queue_int_advance();
- break;
- }
-
- // if (stack_manager_get_interface()->get_stack_is_running())
- if (stack_manager_is_stack_running()) {
- btif_queue_connect_next();
- }
-}
-
-/*******************************************************************************
-**
-** Function btif_queue_connect
-**
-** Description Add a new connection to the queue and trigger the next
-** scheduled connection.
-**
-** Returns BT_STATUS_SUCCESS if successful
-**
-*******************************************************************************/
-bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb)
-{
- connect_node_t node;
- memset(&node, 0, sizeof(connect_node_t));
- memcpy(&node.bda, bda, sizeof(bt_bdaddr_t));
- node.uuid = uuid;
- node.connect_cb = connect_cb;
-
- return btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_CONNECT_EVT,
- (char *)&node, sizeof(connect_node_t), NULL);
-}
-
-/*******************************************************************************
-**
-** Function btif_queue_advance
-**
-** Description Clear the queue's busy status and advance to the next
-** scheduled connection.
-**
-** Returns void
-**
-*******************************************************************************/
-void btif_queue_advance()
-{
- btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT,
- NULL, 0, NULL);
-}
-
-// This function dispatches the next pending connect request. It is called from
-// stack_manager when the stack comes up.
-bt_status_t btif_queue_connect_next(void)
-{
- if (!connect_queue || list_is_empty(connect_queue)) {
- return BT_STATUS_FAIL;
- }
-
- connect_node_t *p_head = list_front(connect_queue);
-
- // If the queue is currently busy, we return success anyway,
- // since the connection has been queued...
- if (p_head->busy) {
- return BT_STATUS_SUCCESS;
- }
-
- p_head->busy = true;
- return p_head->connect_cb(&p_head->bda, p_head->uuid);
-}
-
-
-/*******************************************************************************
-**
-** Function btif_queue_release
-**
-** Description Free up all the queue nodes and set the queue head to NULL
-**
-** Returns void
-**
-*******************************************************************************/
-void btif_queue_release()
-{
- list_free(connect_queue);
- connect_queue = NULL;
-}
bluedroid/btc/profile/std/gap \
bluedroid/btc/profile/std/gatt \
bluedroid/btc/profile/std/a2dp \
+ bluedroid/btc/profile/std/avrc \
bluedroid/btc/profile \
bluedroid/stack/btm \
bluedroid/stack/btu \
esp_bt_gap_set_device_name(dev_name);
- // esp_a2d_register_callback(&bt_app_a2d_cb);
- // esp_a2d_register_data_callback(bt_app_a2d_data_cb);
+ esp_a2d_register_callback(&bt_app_a2d_cb);
+ esp_a2d_register_data_callback(bt_app_a2d_data_cb);
- // esp_a2d_sink_init();
+ esp_a2d_sink_init();
- // esp_avrc_ct_init();
- // esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
+ esp_avrc_ct_init();
+ esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
break;