diff options
-rwxr-xr-x[-rw-r--r--] | bta/av/bta_av_act.c | 65 | ||||
-rwxr-xr-x[-rw-r--r--] | bta/av/bta_av_cfg.c | 20 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/include/btif_av.h | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/include/btif_util.h | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/src/bluetooth.c | 8 | ||||
-rwxr-xr-x | btif/src/btif_av.c | 10 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/src/btif_rc.c | 724 | ||||
-rwxr-xr-x[-rw-r--r--] | btif/src/btif_util.c | 58 | ||||
-rwxr-xr-x[-rw-r--r--] | include/bt_target.h | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/Android.mk | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_api.c | 486 | ||||
-rwxr-xr-x | stack/avrc/avrc_bld_tg.c | 903 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_int.h | 21 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_opt.c | 7 | ||||
-rwxr-xr-x | stack/avrc/avrc_pars_tg.c | 305 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_sdp.c | 11 | ||||
-rwxr-xr-x | stack/avrc/avrc_utils.c | 240 |
17 files changed, 2806 insertions, 75 deletions
diff --git a/bta/av/bta_av_act.c b/bta/av/bta_av_act.c index edf8b7fd3..e13b41fa0 100644..100755 --- a/bta/av/bta_av_act.c +++ b/bta/av/bta_av_act.c @@ -760,6 +760,8 @@ tBTA_AV_EVT bta_av_proc_meta_cmd(tAVRC_RESPONSE *p_rc_rsp, tBTA_AV_RC_MSG *p_ms UINT16 u16; tAVRC_MSG_VENDOR *p_vendor = &p_msg->msg.vendor; +#if (AVRC_METADATA_INCLUDED == TRUE) + pdu = *(p_vendor->p_vendor_data); p_rc_rsp->pdu = pdu; *p_ctype = AVRC_RSP_REJ; @@ -772,6 +774,13 @@ tBTA_AV_EVT bta_av_proc_meta_cmd(tAVRC_RESPONSE *p_rc_rsp, tBTA_AV_RC_MSG *p_ms p_vendor->hdr.ctype = BTA_AV_RSP_NOT_IMPL; AVRC_VendorRsp(p_msg->handle, p_msg->label, &p_msg->msg.vendor); } + else if (!AVRC_IsValidAvcType(pdu, p_vendor->hdr.ctype) ) + { + APPL_TRACE_DEBUG2("Invalid pdu/ctype: 0x%x, %d", pdu, p_vendor->hdr.ctype); + /* reject invalid message without reporting to app */ + evt = 0; + p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD; + } else { switch (pdu) @@ -823,6 +832,12 @@ tBTA_AV_EVT bta_av_proc_meta_cmd(tAVRC_RESPONSE *p_rc_rsp, tBTA_AV_RC_MSG *p_ms } } +#else + APPL_TRACE_DEBUG0("AVRCP 1.3 Metadata not supporteed. Reject command."); + /* reject invalid message without reporting to app */ + evt = 0; + p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD; +#endif return evt; } @@ -844,6 +859,13 @@ void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) BT_HDR *p_pkt = NULL; tAVRC_MSG_VENDOR *p_vendor = &p_data->rc_msg.msg.vendor; BOOLEAN is_inquiry = ((p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_SPEC_INQ) || p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_GEN_INQ); +#if (AVRC_METADATA_INCLUDED == TRUE) + tAVRC_STS res; + UINT8 ctype; + tAVRC_RESPONSE rc_rsp; + + rc_rsp.rsp.status = BTA_AV_STS_NO_RSP; +#endif if (p_data->rc_msg.opcode == AVRC_OP_PASS_THRU) { @@ -857,6 +879,12 @@ void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) if (p_data->rc_msg.msg.pass.op_id == AVRC_ID_VENDOR) { p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL; +#if (AVRC_METADATA_INCLUDED == TRUE) + if (p_cb->features & BTA_AV_FEAT_METADATA) + p_data->rc_msg.msg.hdr.ctype = + bta_av_group_navi_supported(p_data->rc_msg.msg.pass.pass_len, + p_data->rc_msg.msg.pass.p_pass_data, is_inquiry); +#endif } else { @@ -912,12 +940,30 @@ void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) if ((p_cb->features & BTA_AV_FEAT_VENDOR) && p_data->rc_msg.msg.hdr.ctype <= AVRC_CMD_GEN_INQ) { +#if (AVRC_METADATA_INCLUDED == TRUE) + if ((p_cb->features & BTA_AV_FEAT_METADATA) && + (p_vendor->company_id == AVRC_CO_METADATA)) + { + av.meta_msg.p_msg = &p_data->rc_msg.msg; + evt = bta_av_proc_meta_cmd (&rc_rsp, &p_data->rc_msg, &ctype); + } + else +#endif evt = BTA_AV_VENDOR_CMD_EVT; } /* else if configured to support vendor specific and it's a response */ else if ((p_cb->features & BTA_AV_FEAT_VENDOR) && p_data->rc_msg.msg.hdr.ctype >= AVRC_RSP_ACCEPT) { +#if (AVRC_METADATA_INCLUDED == TRUE) + if ((p_cb->features & BTA_AV_FEAT_METADATA) && + (p_vendor->company_id == AVRC_CO_METADATA)) + { + av.meta_msg.p_msg = &p_data->rc_msg.msg; + evt = BTA_AV_META_MSG_EVT; + } + else +#endif evt = BTA_AV_VENDOR_RSP_EVT; } @@ -936,6 +982,18 @@ void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data) AVRC_VendorRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.vendor); } } +#if (AVRC_METADATA_INCLUDED == TRUE) + if (evt == 0 && rc_rsp.rsp.status != BTA_AV_STS_NO_RSP) + { + if (!p_pkt) + { + rc_rsp.rsp.opcode = p_data->rc_msg.opcode; + res = AVRC_BldResponse (0, &rc_rsp, &p_pkt); + } + if (p_pkt) + AVRC_MsgReq (p_data->rc_msg.handle, p_data->rc_msg.label, ctype, p_pkt); + } +#endif /* call callback */ if (evt != 0) @@ -1655,7 +1713,12 @@ void bta_av_rc_disc_done(tBTA_AV_DATA *p_data) APPL_TRACE_DEBUG1("rc_handle %d", rc_handle); /* check peer version and whether support CT and TG role */ peer_features = bta_av_check_peer_features (UUID_SERVCLASS_AV_REMOTE_CONTROL); - peer_features |= bta_av_check_peer_features (UUID_SERVCLASS_AV_REM_CTRL_TARGET); + if ((p_cb->features & BTA_AV_FEAT_ADV_CTRL) && ((peer_features&BTA_AV_FEAT_ADV_CTRL) == 0)) + { + /* if we support advance control and peer does not, check their support on TG role + * some implementation uses 1.3 on CT ans 1.4 on TG */ + peer_features |= bta_av_check_peer_features (UUID_SERVCLASS_AV_REM_CTRL_TARGET); + } p_cb->disc = 0; utl_freebuf((void **) &p_cb->p_disc_db); diff --git a/bta/av/bta_av_cfg.c b/bta/av/bta_av_cfg.c index f589a8870..604f0a555 100644..100755 --- a/bta/av/bta_av_cfg.c +++ b/bta/av/bta_av_cfg.c @@ -28,13 +28,10 @@ #include "bta_api.h" #include "bta_av_int.h" - - #ifndef BTA_AV_RC_PASS_RSP_CODE #define BTA_AV_RC_PASS_RSP_CODE BTA_AV_RSP_NOT_IMPL #endif - const UINT32 bta_av_meta_caps_co_ids[] = { AVRC_CO_METADATA, AVRC_CO_BROADCOM @@ -43,7 +40,6 @@ const UINT32 bta_av_meta_caps_co_ids[] = { /* AVRCP cupported categories */ #define BTA_AV_RC_SUPF_CT (AVRC_SUPF_CT_CAT2) - /* Added to modify ** 1. flush timeout ** 2. Remove Group navigation support in SupportedFeatures @@ -62,8 +58,12 @@ const UINT16 bta_av_audio_flush_to[] = { }; /* AVDTP audio transport channel flush timeout */ /* Note: Android doesnt support AVRC_SUPF_TG_GROUP_NAVI */ +/* Note: if AVRC_SUPF_TG_GROUP_NAVI is set, bta_av_cfg.avrc_group should be TRUE */ +#if AVRC_METADATA_INCLUDED == TRUE +#define BTA_AV_RC_SUPF_TG (AVRC_SUPF_TG_CAT1) /* TODO: | AVRC_SUPF_TG_APP_SETTINGS) */ +#else #define BTA_AV_RC_SUPF_TG (AVRC_SUPF_TG_CAT1) - +#endif /* * If the number of event IDs is changed in this array, BTA_AV_ NUM_RC_EVT_IDS also needs to be changed. @@ -71,8 +71,9 @@ const UINT16 bta_av_audio_flush_to[] = { const UINT8 bta_av_meta_caps_evt_ids[] = { AVRC_EVT_PLAY_STATUS_CHANGE, AVRC_EVT_TRACK_CHANGE, - AVRC_EVT_PLAY_POS_CHANGED, - AVRC_EVT_APP_SETTING_CHANGE, + /* TODO: Add support for these events */ + /* AVRC_EVT_PLAY_POS_CHANGED, + AVRC_EVT_APP_SETTING_CHANGE, */ }; #ifndef BTA_AV_NUM_RC_EVT_IDS #define BTA_AV_NUM_RC_EVT_IDS (sizeof(bta_av_meta_caps_evt_ids) / sizeof(bta_av_meta_caps_evt_ids[0])) @@ -88,8 +89,13 @@ const UINT8 bta_av_meta_caps_evt_ids[] = { const tBTA_AV_CFG bta_av_cfg = { AVRC_CO_BROADCOM, /* AVRCP Company ID */ +#if AVRC_METADATA_INCLUDED == TRUE + 512, /* AVRCP MTU at L2CAP for control channel */ + BTA_AV_MAX_RC_BR_MTU, /* AVRCP MTU at L2CAP for browsing channel */ +#else 48, /* AVRCP MTU at L2CAP for control channel */ BTA_AV_MAX_RC_BR_MTU, /* AVRCP MTU at L2CAP for browsing channel */ +#endif BTA_AV_RC_SUPF_CT, /* AVRCP controller categories */ BTA_AV_RC_SUPF_TG, /* AVRCP target categories */ 672, /* AVDTP signaling channel MTU at L2CAP */ diff --git a/btif/include/btif_av.h b/btif/include/btif_av.h index c6bd20a41..1053e6cc8 100644..100755 --- a/btif/include/btif_av.h +++ b/btif/include/btif_av.h @@ -113,4 +113,16 @@ void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len); bt_status_t btif_av_init(void); +/******************************************************************************* +** +** Function btif_av_is_connected +** +** Description Checks if av has a connected sink +** +** Returns BOOLEAN +** +*******************************************************************************/ + +BOOLEAN btif_av_is_connected(void); + #endif /* BTIF_AV_H */ diff --git a/btif/include/btif_util.h b/btif/include/btif_util.h index ddb469966..30bff6912 100644..100755 --- a/btif/include/btif_util.h +++ b/btif/include/btif_util.h @@ -56,9 +56,11 @@ const char* dump_property_type(bt_property_type_t type); const char* dump_hf_audio_state(UINT16 event); const char* dump_adapter_scan_mode(bt_scan_mode_t mode); const char* dump_thread_evt(bt_cb_thread_evt evt); - const char* dump_av_conn_state(UINT16 event); const char* dump_av_audio_state(UINT16 event); +const char* dump_rc_event(UINT8 event); +const char* dump_rc_notification_event_id(UINT8 event_id); +const char* dump_rc_pdu(UINT8 pdu); int str2bd(char *str, bt_bdaddr_t *addr); char *bd2str(const bt_bdaddr_t *addr, bdstr_t *bdstr); diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index ffeaaaf90..f62bf2875 100644..100755 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c @@ -36,6 +36,7 @@ #include <hardware/bt_hl.h> #include <hardware/bt_pan.h> #include <hardware/bt_gatt.h> +#include <hardware/bt_rc.h> #define LOG_NDDEBUG 0 #define LOG_TAG "bluedroid" @@ -83,6 +84,8 @@ extern bthl_interface_t *btif_hl_get_interface(); extern btpan_interface_t *btif_pan_get_interface(); /* gatt */ extern btgatt_interface_t *btif_gatt_get_interface(); +/* avrc */ +extern btrc_interface_t *btif_rc_get_interface(); /************************************************************************************ ** Functions @@ -322,8 +325,13 @@ static const void* get_profile_interface (const char *profile_id) if (is_profile(profile_id, BT_PROFILE_HEALTH_ID)) return btif_hl_get_interface(); + if (is_profile(profile_id, BT_PROFILE_GATT_ID)) return btif_gatt_get_interface(); + + if (is_profile(profile_id, BT_PROFILE_AV_RC_ID)) + return btif_rc_get_interface(); + return NULL; } diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c index 4419c229c..074164db2 100755 --- a/btif/src/btif_av.c +++ b/btif/src/btif_av.c @@ -123,7 +123,6 @@ static const btif_sm_handler_t btif_av_state_handlers[] = /************************************************************************* ** Extern functions *************************************************************************/ -extern void btif_rc_init(void); 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); @@ -698,9 +697,6 @@ bt_status_t btif_av_init(void) btif_enable_service(BTA_A2DP_SERVICE_ID); - /* Initialize the AVRC CB */ - btif_rc_init(); - /* 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); @@ -928,8 +924,14 @@ bt_status_t btif_av_execute_service(BOOLEAN b_enable) /* 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 */ +#if (AVRC_METADATA_INCLUDED == TRUE) + BTA_AvEnable(BTA_SEC_AUTHENTICATE, + BTA_AV_FEAT_RCTG|BTA_AV_FEAT_METADATA|BTA_AV_FEAT_VENDOR|BTA_AV_FEAT_NO_SCO_SSPD, + bte_av_callback); +#else BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_NO_SCO_SSPD), bte_av_callback); +#endif BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0); } else { diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c index 68ddf5bcf..a67cb64dd 100644..100755 --- a/btif/src/btif_rc.c +++ b/btif/src/btif_rc.c @@ -34,28 +34,86 @@ #define LOG_TAG "BTIF_RC" #include "btif_common.h" +#include "btif_util.h" +#include "btif_av.h" +#include "hardware/bt_rc.h" +#include "uinput.h" /***************************************************************************** ** Constants & Macros ******************************************************************************/ -#define BTIF_RC_USE_UINPUT TRUE -#include "uinput.h" /* cod value for Headsets */ #define COD_AV_HEADSETS 0x0404 +/* for AVRC 1.4 need to change this */ +#define MAX_RC_NOTIFICATIONS AVRC_EVT_APP_SETTING_CHANGE + +#define IDX_GET_PLAY_STATUS_RSP 0 +#define IDX_LIST_APP_ATTR_RSP 1 +#define IDX_LIST_APP_VALUE_RSP 2 +#define IDX_GET_CURR_APP_VAL_RSP 3 +#define IDX_SET_APP_VAL_RSP 4 +#define IDX_GET_APP_ATTR_TXT_RSP 5 +#define IDX_GET_APP_VAL_TXT_RSP 6 +#define IDX_GET_ELEMENT_ATTR_RSP 7 +#define MAX_CMD_QUEUE_LEN 8 + +#define CHECK_RC_CONNECTED \ + BTIF_TRACE_DEBUG1("## %s ##", __FUNCTION__); \ + if(btif_rc_cb.rc_connected == FALSE) \ + { \ + BTIF_TRACE_WARNING1("Function %s() called when RC is not connected", __FUNCTION__); \ + return BT_STATUS_NOT_READY; \ + } + +#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; \ +} + +#define SEND_METAMSG_RSP(index, avrc_rsp) \ +{ \ + if(btif_rc_cb.rc_pdu_info[index].is_rsp_pending == FALSE) \ + { \ + BTIF_TRACE_WARNING1("%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; \ +} /***************************************************************************** ** Local type definitions ******************************************************************************/ typedef struct { + UINT8 bNotify; + UINT8 label; +} btif_rc_reg_notifications_t; + +typedef struct +{ + UINT8 label; + UINT8 ctype; + BOOLEAN is_rsp_pending; +} btif_rc_cmd_ctxt_t; + +/* TODO : Merge btif_rc_reg_notifications_t and btif_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]; } btif_rc_cb_t; -#ifdef BTIF_RC_USE_UINPUT #define MAX_UINPUT_PATHS 3 static const char* uinput_dev_path[] = {"/dev/uinput", "/dev/input/uinput", "/dev/misc/uinput" }; @@ -68,7 +126,7 @@ static int uinput_create(char *name); static int init_uinput (void); static void close_uinput (void); -static struct { +static const struct { const char *name; uint8_t avrcp; uint16_t mapped_id; @@ -80,16 +138,22 @@ static struct { { "FORWARD", AVRC_ID_FORWARD, KEY_NEXTSONG, 0 }, { "BACKWARD", AVRC_ID_BACKWARD, KEY_PREVIOUSSONG, 0 }, { "REWIND", AVRC_ID_REWIND, KEY_REWIND, 0 }, - { "FAST FORWARD", AVRC_ID_FAST_FOR, KEY_FORWARD, 0 }, + { "FAST FORWARD", AVRC_ID_FAST_FOR, KEY_FORWARD, 0 }, { NULL, 0, 0, 0 } }; -#endif /* BTIF_RC_USE_UINPUT */ +static void send_reject_response (UINT8 rc_handle, UINT8 label, + UINT8 pdu, UINT8 status); +static UINT8 opcode_from_pdu(UINT8 pdu); +static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label, + tBTA_AV_CODE code, tAVRC_RESPONSE *pmetamsg_resp); +static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND* p_param, UINT8 ctype, UINT8 label); /***************************************************************************** ** Static variables ******************************************************************************/ static btif_rc_cb_t btif_rc_cb; +static btrc_callbacks_t *bt_rc_callbacks = NULL; /***************************************************************************** ** Static functions @@ -100,21 +164,20 @@ static btif_rc_cb_t btif_rc_cb; ******************************************************************************/ extern BOOLEAN btif_hf_call_terminated_recently(); extern BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod); -extern BOOLEAN btif_av_is_connected(void); + /***************************************************************************** ** Functions ******************************************************************************/ - -#ifdef BTIF_RC_USE_UINPUT /***************************************************************************** ** Local uinput helper functions ******************************************************************************/ int send_event (int fd, uint16_t type, uint16_t code, int32_t value) { struct uinput_event event; - + BTIF_TRACE_DEBUG4("%s type:%u code:%u value:%d", __FUNCTION__, + type, code, value); memset(&event, 0, sizeof(event)); event.type = type; event.code = code; @@ -125,7 +188,11 @@ int send_event (int fd, uint16_t type, uint16_t code, int32_t value) void send_key (int fd, uint16_t key, int pressed) { - if (fd < 0) { + BTIF_TRACE_DEBUG4("%s fd:%d key:%u pressed:%d", __FUNCTION__, + fd, key, pressed); + + if (fd < 0) + { return; } @@ -223,20 +290,9 @@ void close_uinput (void) uinput_fd = -1; } } -#endif // BTA_AVRCP_FORCE_USE_UINPUT -const char *dump_rc_event_name(tBTA_AV_EVT event) -{ - switch(event) { - case BTA_AV_RC_OPEN_EVT: return "BTA_AV_RC_OPEN_EVT"; - case BTA_AV_RC_CLOSE_EVT: return "BTA_AV_RC_CLOSE_EVT"; - case BTA_AV_REMOTE_CMD_EVT: return "BTA_AV_REMOTE_CMD_EVT"; - case BTA_AV_REMOTE_RSP_EVT: return "BTA_AV_REMOTE_RSP_EVT"; - case BTA_AV_VENDOR_CMD_EVT: return "BTA_AV_VENDOR_CMD_EVT"; - case BTA_AV_VENDOR_RSP_EVT: return "BTA_AV_VENDOR_RSP_EVT"; - default: return "UNKNOWN_EVENT"; - } -} + + /*************************************************************************** * Function handle_rc_connect @@ -249,14 +305,30 @@ const char *dump_rc_event_name(tBTA_AV_EVT event) void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open) { BTIF_TRACE_DEBUG2("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle); + bt_status_t result = BT_STATUS_SUCCESS; + int i; + char bd_str[18]; -#ifdef BTIF_RC_USE_UINPUT - init_uinput(); -#endif + if(p_rc_open->status == BTA_AV_SUCCESS) + { + 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_connected = TRUE; + btif_rc_cb.rc_handle = p_rc_open->rc_handle; - memcpy(btif_rc_cb.rc_addr, p_rc_open->peer_addr, sizeof(BD_ADDR)); - btif_rc_cb.rc_connected = TRUE; - btif_rc_cb.rc_handle = p_rc_open->rc_handle; + result = uinput_driver_check(); + if(result == BT_STATUS_SUCCESS) + { + init_uinput(); + } + } + else + { + BTIF_TRACE_ERROR2("%s Connect failed with error code: %d", + __FUNCTION__, p_rc_open->status); + btif_rc_cb.rc_connected = FALSE; + } } /*************************************************************************** @@ -274,9 +346,8 @@ void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close) btif_rc_cb.rc_handle = 0; btif_rc_cb.rc_connected = FALSE; memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR)); -#ifdef BTIF_RC_USE_UINPUT + btif_rc_cb.rc_features = 0; close_uinput(); -#endif /* BTIF_RC_USE_UINPUT */ } /*************************************************************************** @@ -293,8 +364,6 @@ void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd) const char *status; int pressed, i; - btif_rc_cb.rc_handle = p_remote_cmd->rc_handle; - /* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up this PLAY */ if (p_remote_cmd) { @@ -357,17 +426,13 @@ void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd) __FUNCTION__, key_map[i].name); return; } -#ifdef BTIF_RC_USE_UINPUT send_key(uinput_fd, key_map[i].mapped_id, pressed); -#endif if ((key_map[i].release_quirk == 1) && (pressed == 1)) { GKI_delay(30); // 30ms BTIF_TRACE_DEBUG2("%s: AVRC %s Release quirk enabled, send release now", __FUNCTION__, key_map[i].name); -#ifdef BTIF_RC_USE_UINPUT send_key(uinput_fd, key_map[i].mapped_id, 0); -#endif } break; } @@ -378,23 +443,98 @@ void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd) p_remote_cmd->rc_id, status); } -/***************************************************************************** -** -** Function btif_rc_init -** -** Description Initialize RC -** -** Returns Returns 0 on success, -1 otherwise -** -*******************************************************************************/ -int btif_rc_init() +void handle_uid_changed_notification(tBTA_AV_META_MSG *pmeta_msg, tAVRC_COMMAND *pavrc_command) { - BTIF_TRACE_DEBUG1("%s", __FUNCTION__); - memset (&btif_rc_cb, 0, sizeof(btif_rc_cb)); + tAVRC_RESPONSE avrc_rsp = {0}; + avrc_rsp.rsp.pdu = pavrc_command->pdu; + avrc_rsp.rsp.status = AVRC_STS_NO_ERROR; + avrc_rsp.rsp.opcode = pavrc_command->cmd.opcode; + + avrc_rsp.reg_notif.event_id = pavrc_command->reg_notif.event_id; + avrc_rsp.reg_notif.param.uid_counter = 0; + + send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_INTERIM, &avrc_rsp); + send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_CHANGED, &avrc_rsp); -#ifdef BTIF_RC_USE_UINPUT - return uinput_driver_check(); -#endif /* BTIF_RC_USE_UINPUT */ +} + + +/*************************************************************************** + * Function handle_rc_metamsg_cmd + * + * - Argument: tBTA_AV_VENDOR Structure containing the received + * metamsg command + * + * - Description: Remote control metamsg command handler (AVRCP 1.3) + * + ***************************************************************************/ +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; + int param_len; + + BTIF_TRACE_EVENT1("+ %s", __FUNCTION__); + + if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR) + { + BTIF_TRACE_WARNING1("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode); + return; + } + if (pmeta_msg->len < 3) + { + BTIF_TRACE_WARNING2("Invalid length.Opcode: 0x%x, len: 0x%x", pmeta_msg->p_msg->hdr.opcode, + pmeta_msg->len); + return; + } + + if (pmeta_msg->code >= AVRC_RSP_NOT_IMPL) + { + BTIF_TRACE_DEBUG3("%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)); + + if (status != AVRC_STS_NO_ERROR) + { + /* return error */ + BTIF_TRACE_WARNING2("%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); + } + else + { + /* if RegisterNotification, add it to our registered queue */ + + if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION) + { + UINT8 event_id = avrc_command.reg_notif.event_id; + param_len = sizeof(tAVRC_REG_NOTIF_CMD); + BTIF_TRACE_EVENT3("%s: New register notification received. event_id:%s, label:0x%x", + __FUNCTION__, dump_rc_notification_event_id(event_id), pmeta_msg->label); + btif_rc_cb.rc_notif[event_id-1].bNotify = TRUE; + btif_rc_cb.rc_notif[event_id-1].label = pmeta_msg->label; + + if(event_id == AVRC_EVT_UIDS_CHANGE) + { + handle_uid_changed_notification(pmeta_msg, &avrc_command); + return; + } + + } + + BTIF_TRACE_EVENT2("%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, + pmeta_msg->label); + } } /*************************************************************************** @@ -406,7 +546,7 @@ int btif_rc_init() ***************************************************************************/ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data) { - BTIF_TRACE_DEBUG2 ("%s event:%s", __FUNCTION__, dump_rc_event_name(event)); + BTIF_TRACE_DEBUG2 ("%s event:%s", __FUNCTION__, dump_rc_event(event)); switch (event) { case BTA_AV_RC_OPEN_EVT: @@ -425,9 +565,27 @@ void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data) BTIF_TRACE_DEBUG2("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) ); - }break; + } + break; + case BTA_AV_RC_FEAT_EVT: + { + BTIF_TRACE_DEBUG1("Peer_features:%x", p_data->rc_feat.peer_features); + btif_rc_cb.rc_features = p_data->rc_feat.peer_features; + /* TODO Handle RC_FEAT_EVT*/ + } + break; + case BTA_AV_META_MSG_EVT: + { + BTIF_TRACE_DEBUG2("BTA_AV_META_MSG_EVT code:%d label:%d", p_data->meta_msg.code, + p_data->meta_msg.label); + BTIF_TRACE_DEBUG3(" 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_DEBUG0("Unhandled RC event"); + BTIF_TRACE_DEBUG1("Unhandled RC event : 0x%x", event); } } @@ -458,7 +616,7 @@ BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr) /* 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) { - ALOGV("btapp_rc_check_handle_pending_play: bSendToApp=%d", bSendToApp); + BTIF_TRACE_DEBUG2("%s: bSendToApp=%d", __FUNCTION__, bSendToApp); if (btif_rc_cb.rc_pending_play) { if (bSendToApp) @@ -490,3 +648,455 @@ void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp) } } +/* Generic reject response */ +static void send_reject_response (UINT8 rc_handle, UINT8 label, UINT8 pdu, UINT8 status) +{ + UINT8 ctype = AVRC_RSP_REJ; + tAVRC_RESPONSE avrc_rsp; + BT_HDR *p_msg = NULL; + memset (&avrc_rsp, 0, sizeof(tAVRC_RESPONSE)); + + avrc_rsp.rsp.opcode = opcode_from_pdu(pdu); + avrc_rsp.rsp.pdu = pdu; + avrc_rsp.rsp.status = status; + + if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(rc_handle, &avrc_rsp, &p_msg)) ) + { + BTIF_TRACE_DEBUG4("%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); + } +} + +/*************************************************************************** + * Function send_metamsg_rsp + * + * - Argument: + * rc_handle RC handle corresponding to the connected RC + * label Label of the RC response + * code Response type + * pmetamsg_resp Vendor response + * + * - Description: Remote control metamsg response handler (AVRCP 1.3) + * + ***************************************************************************/ +static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label, tBTA_AV_CODE code, + tAVRC_RESPONSE *pmetamsg_resp) +{ + UINT8 ctype; + tAVRC_STS status; + + if (!pmetamsg_resp) + { + BTIF_TRACE_WARNING1("%s: Invalid response received from application", __FUNCTION__); + return; + } + + BTIF_TRACE_EVENT5("+%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) + { + ctype = AVRC_RSP_REJ; + } + else + { + if ( code < AVRC_RSP_NOT_IMPL) + { + if (code == AVRC_CMD_NOTIF) + { + ctype = AVRC_RSP_INTERIM; + } + else if (code == AVRC_CMD_STATUS) + { + ctype = AVRC_RSP_IMPL_STBL; + } + else + { + ctype = AVRC_RSP_ACCEPT; + } + } + else + { + ctype = code; + } + } + /* if response is for register_notification, make sure the rc has + actually registered for this */ + if((pmetamsg_resp->rsp.pdu == AVRC_PDU_REGISTER_NOTIFICATION) && (code == AVRC_RSP_CHANGED)) + { + 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); + + /* de-register this notification for a CHANGED response */ + btif_rc_cb.rc_notif[event_id-1].bNotify = FALSE; + BTIF_TRACE_DEBUG4("%s rc_handle: %d. event_id: 0x%02d bNotify:%u", __FUNCTION__, + btif_rc_cb.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, + pmetamsg_resp, &p_msg)) ) + { + BTIF_TRACE_DEBUG3("%s Sending notification to rc_handle: %d. event_id: 0x%02d", + __FUNCTION__, btif_rc_cb.rc_handle, event_id); + bSent = TRUE; + BTA_AvMetaRsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label, + ctype, p_msg); + } + else + { + BTIF_TRACE_WARNING2("%s failed to build metamsg response. status: 0x%02x", + __FUNCTION__, status); + } + + } + + if (!bSent) + { + BTIF_TRACE_DEBUG2("%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 + { + /* All other commands go here */ + + BT_HDR *p_msg = NULL; + tAVRC_STS status; + + status = AVRC_BldResponse(rc_handle, pmetamsg_resp, &p_msg); + + if (status == AVRC_STS_NO_ERROR) + { + BTA_AvMetaRsp(rc_handle, label, ctype, p_msg); + } + else + { + BTIF_TRACE_ERROR2("%s: failed to build metamsg response. status: 0x%02x", + __FUNCTION__, status); + } + } +} + +static UINT8 opcode_from_pdu(UINT8 pdu) +{ + UINT8 opcode = 0; + + switch (pdu) + { + case AVRC_PDU_NEXT_GROUP: + case AVRC_PDU_PREV_GROUP: /* pass thru */ + opcode = AVRC_OP_PASS_THRU; + break; + + default: /* vendor */ + opcode = AVRC_OP_VENDOR; + break; + } + + return opcode; +} + +/******************************************************************************* +** +** Function btif_rc_upstreams_evt +** +** Description Executes AVRC UPSTREAMS events in btif context. +** +** Returns void +** +*******************************************************************************/ +static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 ctype, UINT8 label) +{ + BTIF_TRACE_EVENT5("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__, + dump_rc_pdu(pavrc_cmd->pdu), btif_rc_cb.rc_handle, ctype, label); + + switch (event) + { + case AVRC_PDU_GET_PLAY_STATUS: + { + FILL_PDU_QUEUE(IDX_GET_PLAY_STATUS_RSP, ctype, label, TRUE) + HAL_CBACK(bt_rc_callbacks, get_play_status_cb); + } + break; + case AVRC_PDU_LIST_PLAYER_APP_ATTR: + case AVRC_PDU_LIST_PLAYER_APP_VALUES: + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: + case AVRC_PDU_SET_PLAYER_APP_VALUE: + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: + { + /* TODO: Add support for Application Settings */ + } + break; + case AVRC_PDU_GET_ELEMENT_ATTR: + { + btrc_media_attr_t element_attrs[BTRC_MAX_ELEM_ATTR_SIZE]; + UINT8 num_attr; + memset(&element_attrs, 0, sizeof(btrc_media_attr_t)*(BTRC_MAX_ELEM_ATTR_SIZE-1)); + if (pavrc_cmd->get_elem_attrs.num_attr == 0) + { + /* CT requests for all attributes */ + int attr_cnt; + num_attr = (BTRC_MAX_ELEM_ATTR_SIZE - 1); + for (attr_cnt = 1; attr_cnt < BTRC_MAX_ELEM_ATTR_SIZE; attr_cnt++) + { + element_attrs[attr_cnt-1] = attr_cnt; + } + } + else if (pavrc_cmd->get_elem_attrs.num_attr == 0xFF) + { + /* 0xff indicates, no attributes requested */ + num_attr = 0; + } + else + { + num_attr = pavrc_cmd->get_elem_attrs.num_attr; + memcpy(element_attrs, pavrc_cmd->get_elem_attrs.attrs, sizeof(UINT32) + *pavrc_cmd->get_elem_attrs.num_attr); + } + FILL_PDU_QUEUE(IDX_GET_ELEMENT_ATTR_RSP, ctype, label, TRUE); + HAL_CBACK(bt_rc_callbacks, get_element_attr_cb, num_attr, element_attrs); + } + break; + case AVRC_PDU_REGISTER_NOTIFICATION: + { + if(pavrc_cmd->reg_notif.event_id == BTRC_EVT_PLAY_POS_CHANGED && + pavrc_cmd->reg_notif.param == 0) + { + BTIF_TRACE_WARNING1("%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); + /* de-register this notification for a rejected response */ + btif_rc_cb.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, + pavrc_cmd->reg_notif.param); + } + break; + case AVRC_PDU_INFORM_DISPLAY_CHARSET: + { + tAVRC_RESPONSE avrc_rsp; + BTIF_TRACE_EVENT1("%s() AVRC_PDU_INFORM_DISPLAY_CHARSET", __FUNCTION__); + if(btif_rc_cb.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); + } + } + break; + default: + { + send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, + (pavrc_cmd->pdu == AVRC_PDU_SEARCH)?AVRC_STS_SEARCH_NOT_SUP:AVRC_STS_BAD_CMD); + return; + } + 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_EVENT1("## %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)); + + 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; + UINT32 i; + 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 = ((play_status !=BTRC_PLAYSTATE_ERROR)? + AVRC_STS_NO_ERROR:AVRC_STS_BAD_PARAM); + /* 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; + uint8_t j; + 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_DEBUG5("%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_EVENT2("## %s ## event_id:%s", __FUNCTION__, dump_rc_notification_event_id(event_id)); + 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; + break; + case BTRC_EVT_TRACK_CHANGE: + memcpy(&(avrc_rsp.reg_notif.param.track), &(p_param->track), sizeof(btrc_uid_t)); + break; + default: + BTIF_TRACE_WARNING2("%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 cleanup +** +** Description Closes the AVRC interface +** +** Returns void +** +***************************************************************************/ +static void cleanup() +{ + BTIF_TRACE_EVENT1("## %s ##", __FUNCTION__); + close_uinput(); + if (bt_rc_callbacks) + { + bt_rc_callbacks = NULL; + } + memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t)); +} + + +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, + cleanup, +}; + +/******************************************************************************* +** +** Function btif_rc_get_interface +** +** Description Get the AVRCP callback interface +** +** Returns btav_interface_t +** +*******************************************************************************/ +const btrc_interface_t *btif_rc_get_interface(void) +{ + BTIF_TRACE_EVENT1("%s", __FUNCTION__); + return &bt_rc_interface; +} diff --git a/btif/src/btif_util.c b/btif/src/btif_util.c index 0096effe9..636c1bcbb 100644..100755 --- a/btif/src/btif_util.c +++ b/btif/src/btif_util.c @@ -45,7 +45,9 @@ #include "btif_dm.h" #include "btif_util.h" #include "bta_ag_api.h" +#include "bta_av_api.h" #include "bta_hh_api.h" +#include "avrc_defs.h" @@ -460,4 +462,60 @@ const char* dump_bt_status(bt_status_t status) } } +const char *dump_rc_event(UINT8 event) +{ + switch(event) { + 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_META_MSG_EVT) + default: + return "UNKNOWN_EVENT"; + } +} + +const char * dump_rc_notification_event_id(UINT8 event_id) +{ + switch(event_id) + { + CASE_RETURN_STR(AVRC_EVT_PLAY_STATUS_CHANGE) + CASE_RETURN_STR(AVRC_EVT_TRACK_CHANGE) + CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END) + CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_START) + CASE_RETURN_STR(AVRC_EVT_PLAY_POS_CHANGED) + CASE_RETURN_STR(AVRC_EVT_BATTERY_STATUS_CHANGE) + CASE_RETURN_STR(AVRC_EVT_SYSTEM_STATUS_CHANGE) + CASE_RETURN_STR(AVRC_EVT_APP_SETTING_CHANGE) + + default: + return "Unhandled Event ID"; + } +} + +const char* dump_rc_pdu(UINT8 pdu) +{ + switch(pdu) + { + CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_ATTR) + CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_VALUES) + CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE) + CASE_RETURN_STR(AVRC_PDU_SET_PLAYER_APP_VALUE) + CASE_RETURN_STR(AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT) + CASE_RETURN_STR(AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT) + CASE_RETURN_STR(AVRC_PDU_INFORM_DISPLAY_CHARSET) + CASE_RETURN_STR(AVRC_PDU_INFORM_BATTERY_STAT_OF_CT) + CASE_RETURN_STR(AVRC_PDU_GET_ELEMENT_ATTR) + CASE_RETURN_STR(AVRC_PDU_GET_PLAY_STATUS) + CASE_RETURN_STR(AVRC_PDU_REGISTER_NOTIFICATION) + CASE_RETURN_STR(AVRC_PDU_REQUEST_CONTINUATION_RSP) + CASE_RETURN_STR(AVRC_PDU_ABORT_CONTINUATION_RSP) + + default: + return "Unknown PDU"; + } +} + diff --git a/include/bt_target.h b/include/bt_target.h index 98968f54f..8161b8b7d 100644..100755 --- a/include/bt_target.h +++ b/include/bt_target.h @@ -3473,6 +3473,10 @@ Range: Minimum 12000 (12 secs) when supporting PBF. #define AVRC_INCLUDED TRUE #endif +#ifndef AVRC_METADATA_INCLUDED +#define AVRC_METADATA_INCLUDED TRUE +#endif + /****************************************************************************** ** ** MCAP diff --git a/stack/Android.mk b/stack/Android.mk index e17f4c820..f677ad239 100644..100755 --- a/stack/Android.mk +++ b/stack/Android.mk @@ -45,6 +45,9 @@ LOCAL_SRC_FILES:= \ ./avrc/avrc_api.c \ ./avrc/avrc_sdp.c \ ./avrc/avrc_opt.c \ + ./avrc/avrc_bld_tg.c \ + ./avrc/avrc_pars_tg.c \ + ./avrc/avrc_utils.c \ ./hid/hidh_api.c \ ./hid/hidh_conn.c \ ./bnep/bnep_main.c \ diff --git a/stack/avrc/avrc_api.c b/stack/avrc/avrc_api.c index b6347d751..c2e36d7fb 100644..100755 --- a/stack/avrc/avrc_api.c +++ b/stack/avrc/avrc_api.c @@ -18,7 +18,7 @@ /****************************************************************************** * - * nterface to AVRCP mandatory commands + * Interface to AVRCP mandatory commands * ******************************************************************************/ #include <string.h> @@ -111,6 +111,352 @@ static UINT8 * avrc_get_data_ptr(BT_HDR *p_pkt) return p_data; } +#if (AVRC_METADATA_INCLUDED == TRUE) +/****************************************************************************** +** +** Function avrc_prep_end_frag +** +** Description This function prepares an end response fragment +** +** Returns Nothing. +** +******************************************************************************/ +static void avrc_prep_end_frag(UINT8 handle) +{ + tAVRC_FRAG_CB *p_fcb; + BT_HDR *p_pkt_new; + UINT8 *p_data, *p_orig_data; + UINT8 rsp_type; + + AVRC_TRACE_DEBUG0 ("avrc_prep_end_frag" ); + p_fcb = &avrc_cb.fcb[handle]; + + /* The response type of the end fragment should be the same as the the PDU of "End Fragment + ** Respose" Errata: https://www.bluetooth.org/errata/errata_view.cfm?errata_id=4383 */ + p_orig_data = ((UINT8 *)(p_fcb->p_fmsg + 1) + p_fcb->p_fmsg->offset); + rsp_type = ((*p_orig_data) & AVRC_CTYPE_MASK); + + p_pkt_new = p_fcb->p_fmsg; + p_pkt_new->len -= (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + p_pkt_new->offset += (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + p_data = (UINT8 *)(p_pkt_new+1) + p_pkt_new->offset; + *p_data++ = rsp_type; + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_VENDOR; + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + *p_data++ = p_fcb->frag_pdu; + *p_data++ = AVRC_PKT_END; + /* 4=pdu, pkt_type & len */ + UINT16_TO_BE_STREAM(p_data, (p_pkt_new->len - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE)); +} + +/****************************************************************************** +** +** Function avrc_send_continue_frag +** +** Description This function sends a continue response fragment +** +** Returns Nothing. +** +******************************************************************************/ +static void avrc_send_continue_frag(UINT8 handle, UINT8 label) +{ + tAVRC_FRAG_CB *p_fcb; + BT_HDR *p_pkt_old, *p_pkt; + UINT8 *p_old, *p_data; + UINT8 cr = AVCT_RSP; + tAVRC_RSP rej_rsp; + + p_fcb = &avrc_cb.fcb[handle]; + p_pkt = p_fcb->p_fmsg; + + AVRC_TRACE_DEBUG1 ("avrc_send_continue_frag len(%d) / AVRC_MAX_CTRL_DATA_LEN", p_pkt->len ); + if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) + { + p_pkt_old = p_fcb->p_fmsg; + p_pkt = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + AVCT_MSG_OFFSET + BT_HDR_SIZE)); + if (p_pkt) + { + p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; + p_pkt->offset = AVCT_MSG_OFFSET; + p_pkt->layer_specific = p_pkt_old->layer_specific; + p_pkt->event = p_pkt_old->event; + p_old = (UINT8 *)(p_pkt_old+1) + p_pkt_old->offset; + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + memcpy (p_data, p_old, AVRC_MAX_CTRL_DATA_LEN); + /* use AVRC continue packet type */ + p_data += AVRC_VENDOR_HDR_SIZE; + p_data++; /* pdu */ + *p_data++ = AVRC_PKT_CONTINUE; + /* 4=pdu, pkt_type & len */ + UINT16_TO_BE_STREAM(p_data, (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - 4)); + + /* prepare the left over for as an end fragment */ + avrc_prep_end_frag (handle); + } + else + { + /* use the current GKI buffer to send Internal error status */ + p_pkt = p_fcb->p_fmsg; + p_fcb->p_fmsg = NULL; + p_fcb->frag_enabled = FALSE; + AVRC_TRACE_ERROR0 ("AVRC_MsgReq no buffers for fragmentation - send internal error" ); + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + *p_data++ = AVRC_PDU_REQUEST_CONTINUATION_RSP; + *p_data++ = 0; + UINT16_TO_BE_STREAM(p_data, 0); + p_pkt->len = 4; + rej_rsp.pdu = AVRC_PDU_REQUEST_CONTINUATION_RSP; + rej_rsp.status = AVRC_STS_INTERNAL_ERR; + AVRC_BldResponse( handle, (tAVRC_RESPONSE *)&rej_rsp, &p_pkt); + cr = AVCT_RSP; + } + } + else + { + /* end fragment. clean the control block */ + p_fcb->frag_enabled = FALSE; + p_fcb->p_fmsg = NULL; + } + AVCT_MsgReq( handle, label, cr, p_pkt); +} + +/****************************************************************************** +** +** Function avrc_proc_vendor_command +** +** Description This function processes received vendor command. +** +** Returns if not NULL, the response to send right away. +** +******************************************************************************/ +static BT_HDR * avrc_proc_vendor_command(UINT8 handle, UINT8 label, + BT_HDR *p_pkt, tAVRC_MSG_VENDOR *p_msg) +{ + BT_HDR *p_rsp = NULL; + UINT8 *p_data; + UINT8 *p_begin; + UINT8 pkt_type; + BOOLEAN abort_frag = FALSE; + tAVRC_STS status = AVRC_STS_NO_ERROR; + tAVRC_FRAG_CB *p_fcb; + + p_begin = (UINT8 *)(p_pkt+1) + p_pkt->offset; + p_data = p_begin + AVRC_VENDOR_HDR_SIZE; + pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; + + if (pkt_type != AVRC_PKT_SINGLE) + { + /* reject - commands can only be in single packets at AVRCP level */ + AVRC_TRACE_ERROR1 ("commands must be in single packet pdu:0x%x", *p_data ); + /* use the current GKI buffer to send the reject */ + status = AVRC_STS_BAD_CMD; + } + /* check if there are fragments waiting to be sent */ + else if (avrc_cb.fcb[handle].frag_enabled) + { + p_fcb = &avrc_cb.fcb[handle]; + if (p_msg->company_id == AVRC_CO_METADATA) + { + switch (*p_data) + { + case AVRC_PDU_ABORT_CONTINUATION_RSP: + /* aborted by CT - send accept response */ + abort_frag = TRUE; + p_begin = (UINT8 *)(p_pkt+1) + p_pkt->offset; + *p_begin = (AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK); + if (*(p_data + 4) != p_fcb->frag_pdu) + { + *p_begin = (AVRC_RSP_REJ & AVRC_CTYPE_MASK); + *(p_data + 4) = AVRC_STS_BAD_PARAM; + } + else + { + p_data = (p_begin + AVRC_VENDOR_HDR_SIZE + 2); + UINT16_TO_BE_STREAM(p_data, 0); + p_pkt->len = (p_data - p_begin); + } + AVCT_MsgReq( handle, label, AVCT_RSP, p_pkt); + p_msg->hdr.opcode = AVRC_OP_DROP; /* used the p_pkt to send response */ + break; + + case AVRC_PDU_REQUEST_CONTINUATION_RSP: + if (*(p_data + 4) == p_fcb->frag_pdu) + { + avrc_send_continue_frag(handle, label); + p_msg->hdr.opcode = AVRC_OP_DROP_N_FREE; + } + else + { + /* the pdu id does not match - reject the command using the current GKI buffer */ + AVRC_TRACE_ERROR2("avrc_proc_vendor_command continue pdu: 0x%x does not match \ + current re-assembly pdu: 0x%x", + *(p_data + 4), p_fcb->frag_pdu); + status = AVRC_STS_BAD_PARAM; + abort_frag = TRUE; + } + break; + + default: + /* implicit abort */ + abort_frag = TRUE; + } + } + else + { + abort_frag = TRUE; + /* implicit abort */ + } + + if (abort_frag) + { + if (p_fcb->p_fmsg) + GKI_freebuf(p_fcb->p_fmsg); + p_fcb->p_fmsg = NULL; + p_fcb->frag_enabled = FALSE; + } + } + + if (status != AVRC_STS_NO_ERROR) + { + /* use the current GKI buffer to build/send the reject message */ + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + *p_data++ = AVRC_RSP_REJ; + p_data += AVRC_VENDOR_HDR_SIZE; /* pdu */ + *p_data++ = 0; /* pkt_type */ + UINT16_TO_BE_STREAM(p_data, 1); /* len */ + *p_data++ = status; /* error code */ + p_pkt->len = AVRC_VENDOR_HDR_SIZE + 5; + p_rsp = p_pkt; + } + + return p_rsp; +} + +/****************************************************************************** +** +** Function avrc_proc_far_msg +** +** Description This function processes vendor command/response fragmetation +** and reassembly +** +** Returns 0, to report the message with msg_cback . +** +******************************************************************************/ +static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_pkt, + tAVRC_MSG_VENDOR *p_msg) +{ + BT_HDR *p_pkt = *pp_pkt; + UINT8 *p_data; + BOOLEAN drop = FALSE; + BT_HDR *p_rsp = NULL; + BT_HDR *p_cmd = NULL; + BOOLEAN req_continue = FALSE; + BT_HDR *p_pkt_new = NULL; + UINT8 pkt_type; + UINT16 buf_len; + tAVRC_RASM_CB *p_rcb; + tAVRC_NEXT_CMD avrc_cmd; + + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; + AVRC_TRACE_DEBUG1 ("pkt_type %d", pkt_type ); + p_rcb = &avrc_cb.rcb[handle]; + if (p_msg->company_id == AVRC_CO_METADATA) + { + /* check if the message needs to be re-assembled */ + if (pkt_type == AVRC_PKT_SINGLE || pkt_type == AVRC_PKT_START) + { + /* previous fragments need to be dropped, when received another new message */ + p_rcb->rasm_offset = 0; + if (p_rcb->p_rmsg) + { + GKI_freebuf(p_rcb->p_rmsg); + p_rcb->p_rmsg = NULL; + } + } + + if (pkt_type != AVRC_PKT_SINGLE && cr == AVCT_RSP) + { + /* not a single response packet - need to re-assemble metadata messages */ + if (pkt_type == AVRC_PKT_START) + { + p_rcb->rasm_offset = p_pkt->offset; + p_rcb->p_rmsg = p_pkt; + /* set offset to point to where to copy next - use the same re-asm logic as AVCT */ + p_rcb->p_rmsg->offset += p_rcb->p_rmsg->len; + p_rcb->rasm_pdu = *p_data; + req_continue = TRUE; + } + else + { + /* get size of buffer holding assembled message */ + buf_len = GKI_get_buf_size (p_rcb->p_rmsg) - sizeof(BT_HDR); + /* adjust offset and len of fragment for header byte */ + p_pkt->offset += (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); + p_pkt->len -= (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); + /* verify length */ + if ((p_rcb->p_rmsg->offset + p_pkt->len) > buf_len) + { + AVRC_TRACE_WARNING0("Fragmented message too big! - report the partial message"); + p_pkt->len = buf_len - p_rcb->p_rmsg->offset; + pkt_type = AVRC_PKT_END; + } + + /* copy contents of p_pkt to p_rx_msg */ + memcpy((UINT8 *)(p_rcb->p_rmsg + 1) + p_rcb->p_rmsg->offset, + (UINT8 *)(p_pkt + 1) + p_pkt->offset, p_pkt->len); + + if (pkt_type == AVRC_PKT_END) + { + p_rcb->p_rmsg->offset = p_rcb->rasm_offset; + p_rcb->p_rmsg->len += p_pkt->len; + p_pkt_new = p_rcb->p_rmsg; + p_rcb->rasm_offset = 0; + p_rcb->p_rmsg = NULL; + p_msg->p_vendor_data = (UINT8 *)(p_pkt_new+1) + p_pkt_new->offset; + p_msg->hdr.ctype = p_msg->p_vendor_data[0] & AVRC_CTYPE_MASK; + /* 6 = ctype, subunit*, opcode & CO_ID */ + p_msg->p_vendor_data += AVRC_VENDOR_HDR_SIZE; + p_msg->vendor_len = p_pkt_new->len - AVRC_VENDOR_HDR_SIZE; + p_data = p_msg->p_vendor_data + 1; /* skip pdu */ + *p_data++ = AVRC_PKT_SINGLE; + UINT16_TO_BE_STREAM(p_data, (p_msg->vendor_len - AVRC_MIN_META_HDR_SIZE)); + AVRC_TRACE_DEBUG3("end frag:%d, total len:%d, offset:%d", p_pkt->len, + p_pkt_new->len, p_pkt_new->offset); + } + else + { + p_rcb->p_rmsg->offset += p_pkt->len; + p_rcb->p_rmsg->len += p_pkt->len; + p_pkt_new = NULL; + req_continue = TRUE; + } + GKI_freebuf(p_pkt); + *pp_pkt = p_pkt_new; + } + } + + if (cr == AVCT_CMD) + { + p_rsp = avrc_proc_vendor_command(handle, label, *pp_pkt, p_msg); + if (p_rsp) + { + AVCT_MsgReq( handle, label, AVCT_RSP, p_rsp); + drop = 3; + } + else if (p_msg->hdr.opcode == AVRC_OP_DROP) + { + drop = 1; + } + else if (p_msg->hdr.opcode == AVRC_OP_DROP_N_FREE) + drop = 4; + + } + } + return drop; +} +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ /****************************************************************************** ** @@ -184,7 +530,8 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, p_rsp = p_pkt; /* this also sets free = FALSE, drop = TRUE */ /* check & set the offset. set response code, set subunit_type & subunit_id, set AVRC_OP_UNIT_INFO */ - p_rsp_data = avrc_get_data_ptr(p_pkt) + AVRC_AVC_HDR_SIZE; /* 3 bytes: ctype, subunit*, opcode */ + /* 3 bytes: ctype, subunit*, opcode */ + p_rsp_data = avrc_get_data_ptr(p_pkt) + AVRC_AVC_HDR_SIZE; *p_rsp_data++ = 7; /* Panel subunit & id=0 */ *p_rsp_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); @@ -256,6 +603,34 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, p_msg->p_vendor_data = p_data; p_msg->vendor_len = p_pkt->len - (p_data - p_begin); +#if (AVRC_METADATA_INCLUDED == TRUE) + drop = avrc_proc_far_msg(handle, label, cr, &p_pkt, p_msg); + if (drop) + { + free = FALSE; + if (drop == 4) + free = TRUE; +#if (BT_USE_TRACES == TRUE) + switch (drop) + { + case 1: + p_drop_msg = "sent_frag"; + break; + case 2: + p_drop_msg = "req_cont"; + break; + case 3: + p_drop_msg = "sent_frag3"; + break; + case 4: + p_drop_msg = "sent_frag_free"; + break; + default: + p_drop_msg = "sent_fragd"; + } +#endif + } +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ break; case AVRC_OP_PASS_THRU: @@ -458,8 +833,13 @@ UINT16 AVRC_Open(UINT8 *p_handle, tAVRC_CONN_CB *p_ccb, BD_ADDR_PTR peer_addr) if (status == AVCT_SUCCESS) { memcpy(&avrc_cb.ccb[*p_handle], p_ccb, sizeof(tAVRC_CONN_CB)); +#if (AVRC_METADATA_INCLUDED == TRUE) + memset(&avrc_cb.fcb[*p_handle], 0, sizeof(tAVRC_FRAG_CB)); + memset(&avrc_cb.rcb[*p_handle], 0, sizeof(tAVRC_RASM_CB)); +#endif } - AVRC_TRACE_DEBUG4("AVRC_Open role: %d, control:%d status:%d, handle:%d", cc.role, cc.control, status, *p_handle); + AVRC_TRACE_DEBUG4("AVRC_Open role: %d, control:%d status:%d, handle:%d", cc.role, cc.control, + status, *p_handle); return status; } @@ -507,8 +887,108 @@ UINT16 AVRC_Close(UINT8 handle) ******************************************************************************/ UINT16 AVRC_MsgReq (UINT8 handle, UINT8 label, UINT8 ctype, BT_HDR *p_pkt) { +#if (AVRC_METADATA_INCLUDED == TRUE) + UINT8 *p_data; + UINT8 cr = AVCT_CMD; + BOOLEAN chk_frag = TRUE; + UINT8 *p_start = NULL; + tAVRC_FRAG_CB *p_fcb; + UINT16 len; + BT_HDR *p_pkt_new; + + if (!p_pkt) + return AVRC_BAD_PARAM; + + if (ctype >= AVRC_RSP_NOT_IMPL) + cr = AVCT_RSP; + + if (p_pkt->event == AVRC_OP_VENDOR) + { + /* add AVRCP Vendor Dependent headers */ + p_start = ((UINT8 *)(p_pkt + 1) + p_pkt->offset); + p_pkt->offset -= AVRC_VENDOR_HDR_SIZE; + p_pkt->len += AVRC_VENDOR_HDR_SIZE; + p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + *p_data++ = (ctype & AVRC_CTYPE_MASK); + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_VENDOR; + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + } + else if (p_pkt->event == AVRC_OP_PASS_THRU) + { + /* add AVRCP Pass Through headers */ + p_start = ((UINT8 *)(p_pkt + 1) + p_pkt->offset); + p_pkt->offset -= AVRC_PASS_THRU_SIZE; + p_pkt->len += AVRC_PASS_THRU_SIZE; + p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + *p_data++ = (ctype & AVRC_CTYPE_MASK); + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_PASS_THRU;/* opcode */ + *p_data++ = AVRC_ID_VENDOR; /* operation id */ + *p_data++ = 5; /* operation data len */ + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + } + + /* abandon previous fragments */ + p_fcb = &avrc_cb.fcb[handle]; + if (p_fcb->frag_enabled) + p_fcb->frag_enabled = FALSE; + + if (p_fcb->p_fmsg) + { + GKI_freebuf(p_fcb->p_fmsg); + p_fcb->p_fmsg = NULL; + } + + /* AVRCP spec has not defined any control channel commands that needs fragmentation at this level + * check for fragmentation only on the response */ + if ((cr == AVCT_RSP) && (chk_frag == TRUE)) + { + if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) + { + AVRC_TRACE_DEBUG1 ("p_pkt->len(%d) > AVRC_MAX_CTRL_DATA_LEN", p_pkt->len ); + p_pkt_new = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + AVCT_MSG_OFFSET + + BT_HDR_SIZE)); + if (p_pkt_new) + { + p_fcb->frag_enabled = TRUE; + p_fcb->p_fmsg = p_pkt; + p_fcb->frag_pdu = *p_start; + p_pkt = p_pkt_new; + p_pkt_new = p_fcb->p_fmsg; + p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; + p_pkt->offset = p_pkt_new->offset; + p_pkt->layer_specific = p_pkt_new->layer_specific; + p_pkt->event = p_pkt_new->event; + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + p_start -= AVRC_VENDOR_HDR_SIZE; + memcpy (p_data, p_start, AVRC_MAX_CTRL_DATA_LEN); + /* use AVRC start packet type */ + p_data += AVRC_VENDOR_HDR_SIZE; + p_data++; /* pdu */ + *p_data++ = AVRC_PKT_START; + /* 4 pdu, pkt_type & len */ + len = (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + UINT16_TO_BE_STREAM(p_data, len); + + /* prepare the left over for as an end fragment */ + avrc_prep_end_frag (handle); + AVRC_TRACE_DEBUG3 ("p_pkt len:%d/%d, next len:%d", p_pkt->len, len, p_fcb->p_fmsg->len ); + } + else + { + AVRC_TRACE_ERROR0 ("AVRC_MsgReq no buffers for fragmentation" ); + GKI_freebuf(p_pkt); return AVRC_NO_RESOURCES; } + } + } + + return AVCT_MsgReq( handle, label, cr, p_pkt); +#else + return AVRC_NO_RESOURCES; +#endif +} /****************************************************************************** diff --git a/stack/avrc/avrc_bld_tg.c b/stack/avrc/avrc_bld_tg.c new file mode 100755 index 000000000..d201b9dc2 --- /dev/null +++ b/stack/avrc/avrc_bld_tg.c @@ -0,0 +1,903 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2013 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. + * + ******************************************************************************/ +#include <string.h> + +#include "gki.h" +#include "avrc_api.h" +#include "avrc_defs.h" +#include "avrc_int.h" + +/***************************************************************************** +** Global data +*****************************************************************************/ +#if (AVRC_METADATA_INCLUDED == TRUE) + +/******************************************************************************* +** +** Function avrc_bld_get_capability_rsp +** +** Description This function builds the Get Capability response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_capability_rsp (tAVRC_GET_CAPS_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len = 0; + UINT8 xx; + UINT32 *p_company_id; + UINT8 *p_event_id; + tAVRC_STS status = AVRC_STS_NO_ERROR; + + if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id))) + { + AVRC_TRACE_ERROR1("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", p_rsp); + status = AVRC_STS_BAD_PARAM; + return status; + } + + AVRC_TRACE_API0("avrc_bld_get_capability_rsp"); + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + UINT8_TO_BE_STREAM(p_data, p_rsp->capability_id); + p_count = p_data; + + if (len == 0) + { + *p_count = p_rsp->count; + p_data++; + len = 2; /* move past the capability_id and count */ + } + else + { + p_data = p_start + p_pkt->len; + *p_count += p_rsp->count; + } + + if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID) + { + p_company_id = p_rsp->param.company_id; + for (xx=0; xx< p_rsp->count; xx++) + { + UINT24_TO_BE_STREAM(p_data, p_company_id[xx]); + } + len += p_rsp->count * 3; + } + else + { + p_event_id = p_rsp->param.event_id; + *p_count = 0; + for (xx=0; xx< p_rsp->count; xx++) + { + if (AVRC_IS_VALID_EVENT_ID(p_event_id[xx])) + { + (*p_count)++; + UINT8_TO_BE_STREAM(p_data, p_event_id[xx]); + } + } + len += (*p_count); + } + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + status = AVRC_STS_NO_ERROR; + + return status; +} + +/******************************************************************************* +** +** Function avrc_bld_list_app_settings_attr_rsp +** +** Description This function builds the List Application Settings Attribute +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_list_app_settings_attr_rsp (tAVRC_LIST_APP_ATTR_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_num; + UINT16 len = 0; + UINT8 xx; + + AVRC_TRACE_API0("avrc_bld_list_app_settings_attr_rsp"); + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_num = p_data; + if (len == 0) + { + /* first time initialize the attribute count */ + *p_num = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_attr; xx++) + { + if(AVRC_IsValidPlayerAttr(p_rsp->attrs[xx])) + { + (*p_num)++; + UINT8_TO_BE_STREAM(p_data, p_rsp->attrs[xx]); + } + } + + len = *p_num + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_list_app_settings_values_rsp +** +** Description This function builds the List Application Setting Values +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_list_app_settings_values_rsp (tAVRC_LIST_APP_VALUES_RSP *p_rsp, + BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_num; + UINT8 xx; + UINT16 len; + + AVRC_TRACE_API0("avrc_bld_list_app_settings_values_rsp"); + + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + /* get the existing length, if any, and also the num attributes */ + BE_STREAM_TO_UINT16(len, p_data); + p_num = p_data; + /* first time initialize the attribute count */ + if (len == 0) + { + *p_num = p_rsp->num_val; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + *p_num += p_rsp->num_val; + } + + + for (xx=0; xx<p_rsp->num_val; xx++) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->vals[xx]); + } + + len = *p_num + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_get_cur_app_setting_value_rsp +** +** Description This function builds the Get Current Application Setting Value +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_cur_app_setting_value_rsp (tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp, + BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len; + UINT8 xx; + + if (!p_rsp->p_vals) + { + AVRC_TRACE_ERROR0("avrc_bld_get_cur_app_setting_value_rsp NULL parameter"); + return AVRC_STS_BAD_PARAM; + } + + AVRC_TRACE_API0("avrc_bld_get_cur_app_setting_value_rsp"); + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + if (len == 0) + { + /* first time initialize the attribute count */ + *p_count = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_val; xx++) + { + if (avrc_is_valid_player_attrib_value(p_rsp->p_vals[xx].attr_id, p_rsp->p_vals[xx].attr_val)) + { + (*p_count)++; + UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_id); + UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_val); + } + } + len = ((*p_count) << 1) + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_set_app_setting_value_rsp +** +** Description This function builds the Set Application Setting Value +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_set_app_setting_value_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_set_app_setting_value_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_app_setting_text_rsp +** +** Description This function builds the Get Application Settings Attribute Text +** or Get Application Settings Value Text response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len, len_left; + UINT8 xx; + tAVRC_STS sts = AVRC_STS_NO_ERROR; + UINT8 num_added = 0; + + if (!p_rsp->p_attrs) + { + AVRC_TRACE_ERROR0("avrc_bld_app_setting_text_rsp NULL parameter"); + return AVRC_STS_BAD_PARAM; + } + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + len_left = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE - p_pkt->offset - p_pkt->len; + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + + if (len == 0) + { + *p_count = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_attr; xx++) + { + if (len_left < (p_rsp->p_attrs[xx].str_len + 4)) + { + AVRC_TRACE_ERROR3("avrc_bld_app_setting_text_rsp out of room (str_len:%d, left:%d)", + xx, p_rsp->p_attrs[xx].str_len, len_left); + p_rsp->num_attr = num_added; + sts = AVRC_STS_INTERNAL_ERR; + break; + } + if ( !p_rsp->p_attrs[xx].str_len || !p_rsp->p_attrs[xx].p_str ) + { + AVRC_TRACE_ERROR1("avrc_bld_app_setting_text_rsp NULL attr text[%d]", xx); + continue; + } + UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].charset_id); + UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].str_len); + ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].p_str, p_rsp->p_attrs[xx].str_len); + (*p_count)++; + num_added++; + } + len = p_data - p_count; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return sts; +} + +/******************************************************************************* +** +** Function avrc_bld_get_app_setting_attr_text_rsp +** +** Description This function builds the Get Application Setting Attribute Text +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_app_setting_attr_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, + BT_HDR *p_pkt) +{ + AVRC_TRACE_API0("avrc_bld_get_app_setting_attr_text_rsp"); + return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); +} + +/******************************************************************************* +** +** Function avrc_bld_get_app_setting_value_text_rsp +** +** Description This function builds the Get Application Setting Value Text +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_app_setting_value_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, + BT_HDR *p_pkt) +{ + AVRC_TRACE_API0("avrc_bld_get_app_setting_value_text_rsp"); + return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); +} + +/******************************************************************************* +** +** Function avrc_bld_inform_charset_rsp +** +** Description This function builds the Inform Displayable Character Set +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_inform_charset_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_inform_charset_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_inform_battery_status_rsp +** +** Description This function builds the Inform Battery Status +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_inform_battery_status_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_inform_battery_status_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_get_elem_attrs_rsp +** +** Description This function builds the Get Element Attributes +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_elem_attrs_rsp (tAVRC_GET_ELEM_ATTRS_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len; + UINT8 xx; + + AVRC_TRACE_API0("avrc_bld_get_elem_attrs_rsp"); + if (!p_rsp->p_attrs) + { + AVRC_TRACE_ERROR0("avrc_bld_get_elem_attrs_rsp NULL parameter"); + return AVRC_STS_BAD_PARAM; + } + + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + + if (len == 0) + { + *p_count = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_attr; xx++) + { + if (!AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_rsp->p_attrs[xx].attr_id)) + { + AVRC_TRACE_ERROR2("avrc_bld_get_elem_attrs_rsp invalid attr id[%d]: %d", xx, p_rsp->p_attrs[xx].attr_id); + continue; + } + if ( !p_rsp->p_attrs[xx].name.p_str ) + { + p_rsp->p_attrs[xx].name.str_len = 0; + } + UINT32_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.charset_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.str_len); + ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.p_str, p_rsp->p_attrs[xx].name.str_len); + (*p_count)++; + } + len = p_data - p_count; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_get_play_status_rsp +** +** Description This function builds the Get Play Status +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_play_status_rsp (tAVRC_GET_PLAY_STATUS_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start; + + AVRC_TRACE_API0("avrc_bld_get_play_status_rsp"); + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; + + /* add fixed lenth - song len(4) + song position(4) + status(1) */ + UINT16_TO_BE_STREAM(p_data, 9); + UINT32_TO_BE_STREAM(p_data, p_rsp->song_len); + UINT32_TO_BE_STREAM(p_data, p_rsp->song_pos); + UINT8_TO_BE_STREAM(p_data, p_rsp->play_status); + p_pkt->len = (p_data - p_start); + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_notify_rsp +** +** Description This function builds the Notification response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_notify_rsp (tAVRC_REG_NOTIF_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start; + UINT8 *p_len; + UINT16 len = 0; + UINT8 xx; + tAVRC_STS status = AVRC_STS_NO_ERROR; + + AVRC_TRACE_API0("avrc_bld_notify_rsp"); + + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + p_data += 2; + + UINT8_TO_BE_STREAM(p_data, p_rsp->event_id); + switch (p_rsp->event_id) + { + case AVRC_EVT_PLAY_STATUS_CHANGE: /* 0x01 */ + /* p_rsp->param.play_status >= AVRC_PLAYSTATE_STOPPED is always TRUE */ + if ((p_rsp->param.play_status <= AVRC_PLAYSTATE_REV_SEEK) || + (p_rsp->param.play_status == AVRC_PLAYSTATE_ERROR) ) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.play_status); + len = 2; + } + else + { + AVRC_TRACE_ERROR0("bad play state"); + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_EVT_TRACK_CHANGE: /* 0x02 */ + ARRAY_TO_BE_STREAM(p_data, p_rsp->param.track, AVRC_UID_SIZE); + len = (UINT8)(AVRC_UID_SIZE + 1); + break; + + case AVRC_EVT_TRACK_REACHED_END: /* 0x03 */ + case AVRC_EVT_TRACK_REACHED_START: /* 0x04 */ + len = 1; + break; + + case AVRC_EVT_PLAY_POS_CHANGED: /* 0x05 */ + UINT32_TO_BE_STREAM(p_data, p_rsp->param.play_pos); + len = 5; + break; + + case AVRC_EVT_BATTERY_STATUS_CHANGE: /* 0x06 */ + if (AVRC_IS_VALID_BATTERY_STATUS(p_rsp->param.battery_status)) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.battery_status); + len = 2; + } + else + { + AVRC_TRACE_ERROR0("bad battery status"); + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_EVT_SYSTEM_STATUS_CHANGE: /* 0x07 */ + if (AVRC_IS_VALID_SYSTEM_STATUS(p_rsp->param.system_status)) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.system_status); + len = 2; + } + else + { + AVRC_TRACE_ERROR0("bad system status"); + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_EVT_APP_SETTING_CHANGE: /* 0x08 */ + if (p_rsp->param.player_setting.num_attr > AVRC_MAX_APP_SETTINGS) + p_rsp->param.player_setting.num_attr = AVRC_MAX_APP_SETTINGS; + + if (p_rsp->param.player_setting.num_attr > 0) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.num_attr); + len = 2; + for (xx=0; xx<p_rsp->param.player_setting.num_attr; xx++) + { + if (avrc_is_valid_player_attrib_value(p_rsp->param.player_setting.attr_id[xx], + p_rsp->param.player_setting.attr_value[xx])) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_id[xx]); + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_value[xx]); + } + else + { + AVRC_TRACE_ERROR0("bad player app seeting attribute or value"); + status = AVRC_STS_BAD_PARAM; + break; + } + len += 2; + } + } + else + status = AVRC_STS_BAD_PARAM; + break; + + default: + status = AVRC_STS_BAD_PARAM; + AVRC_TRACE_ERROR0("unknown event_id"); + } + + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return status; +} + +/******************************************************************************* +** +** Function avrc_bld_next_rsp +** +** Description This function builds the Request Continue or Abort +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_next_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_next_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_group_navigation_rsp +** +** Description This function builds the Group Navigation +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +tAVRC_STS avrc_bld_group_navigation_rsp (UINT16 navi_id, BT_HDR *p_pkt) +{ + UINT8 *p_data; + + if (!AVRC_IS_VALID_GROUP(navi_id)) + { + AVRC_TRACE_ERROR1("avrc_bld_group_navigation_rsp bad navigation op id: %d", navi_id); + return AVRC_STS_BAD_PARAM; + } + + AVRC_TRACE_API0("avrc_bld_group_navigation_rsp"); + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + UINT16_TO_BE_STREAM(p_data, navi_id); + p_pkt->len = 2; + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_rejected_rsp +** +** Description This function builds the General Response response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_rejected_rsp( tAVRC_RSP *p_rsp, BT_HDR *p_pkt ) +{ + UINT8 *p_data, *p_start; + + AVRC_TRACE_API2("avrc_bld_rejected_rsp: status=%d, pdu:x%x", p_rsp->status, p_rsp->pdu); + + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; + AVRC_TRACE_DEBUG1("pdu:x%x", *p_start); + + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + p_pkt->len = p_data - p_start; + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_init_rsp_buffer +** +** Description This function initializes the response buffer based on PDU +** +** Returns NULL, if no GKI buffer or failure to build the message. +** Otherwise, the GKI buffer that contains the initialized message. +** +*******************************************************************************/ +static BT_HDR *avrc_bld_init_rsp_buffer(tAVRC_RESPONSE *p_rsp) +{ + UINT16 offset = AVRC_MSG_PASS_THRU_OFFSET, chnl = AVCT_DATA_CTRL, len=AVRC_META_CMD_POOL_SIZE; + BT_HDR *p_pkt=NULL; + UINT8 opcode = avrc_opcode_from_pdu(p_rsp->pdu); + + AVRC_TRACE_API3("avrc_bld_init_rsp_buffer: pdu=%x, opcode=%x/%x", p_rsp->pdu, opcode, + p_rsp->rsp.opcode); + if (opcode != p_rsp->rsp.opcode && p_rsp->rsp.status != AVRC_STS_NO_ERROR && + avrc_is_valid_opcode(p_rsp->rsp.opcode)) + { + opcode = p_rsp->rsp.opcode; + AVRC_TRACE_API1("opcode=%x", opcode); + } + + switch (opcode) + { + case AVRC_OP_PASS_THRU: + offset = AVRC_MSG_PASS_THRU_OFFSET; + break; + + case AVRC_OP_VENDOR: + offset = AVRC_MSG_VENDOR_OFFSET; + if (p_rsp->pdu == AVRC_PDU_GET_ELEMENT_ATTR) + len = AVRC_BROWSE_POOL_SIZE; + break; + } + + /* allocate and initialize the buffer */ + p_pkt = (BT_HDR *)GKI_getbuf(len); + if (p_pkt) + { + UINT8 *p_data, *p_start; + + p_pkt->layer_specific = chnl; + p_pkt->event = opcode; + p_pkt->offset = offset; + p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_start = p_data; + + /* pass thru - group navigation - has a two byte op_id, so dont do it here */ + if (opcode != AVRC_OP_PASS_THRU) + *p_data++ = p_rsp->pdu; + + switch (opcode) + { + case AVRC_OP_VENDOR: + /* reserved 0, packet_type 0 */ + UINT8_TO_BE_STREAM(p_data, 0); + /* continue to the next "case to add length */ + /* add fixed lenth - 0 */ + UINT16_TO_BE_STREAM(p_data, 0); + break; + } + + p_pkt->len = (p_data - p_start); + } + p_rsp->rsp.opcode = opcode; + return p_pkt; +} + +/******************************************************************************* +** +** Function AVRC_BldResponse +** +** Description This function builds the given AVRCP response to the given +** GKI buffer +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +tAVRC_STS AVRC_BldResponse( UINT8 handle, tAVRC_RESPONSE *p_rsp, BT_HDR **pp_pkt) +{ + tAVRC_STS status = AVRC_STS_BAD_PARAM; + BT_HDR *p_pkt; + BOOLEAN alloc = FALSE; + + if (!p_rsp || !pp_pkt) + { + AVRC_TRACE_API2("AVRC_BldResponse. Invalid parameters passed. p_rsp=%p, pp_pkt=%p", + p_rsp, pp_pkt); + return AVRC_STS_BAD_PARAM; + } + + if (*pp_pkt == NULL) + { + if ((*pp_pkt = avrc_bld_init_rsp_buffer(p_rsp)) == NULL) + { + AVRC_TRACE_API0("AVRC_BldResponse: Failed to initialize response buffer"); + return AVRC_STS_INTERNAL_ERR; + } + alloc = TRUE; + } + status = AVRC_STS_NO_ERROR; + p_pkt = *pp_pkt; + + AVRC_TRACE_API2("AVRC_BldResponse: pdu=%x status=%x", p_rsp->rsp.pdu, p_rsp->rsp.status); + if (p_rsp->rsp.status != AVRC_STS_NO_ERROR) + { + return( avrc_bld_rejected_rsp(&p_rsp->rsp, p_pkt) ); + } + + switch (p_rsp->pdu) + { + case AVRC_PDU_NEXT_GROUP: + case AVRC_PDU_PREV_GROUP: + status = avrc_bld_group_navigation_rsp(p_rsp->pdu, p_pkt); + break; + + case AVRC_PDU_GET_CAPABILITIES: + status = avrc_bld_get_capability_rsp(&p_rsp->get_caps, p_pkt); + break; + + case AVRC_PDU_LIST_PLAYER_APP_ATTR: + status = avrc_bld_list_app_settings_attr_rsp(&p_rsp->list_app_attr, p_pkt); + break; + + case AVRC_PDU_LIST_PLAYER_APP_VALUES: + status = avrc_bld_list_app_settings_values_rsp(&p_rsp->list_app_values, p_pkt); + break; + + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: + status = avrc_bld_get_cur_app_setting_value_rsp(&p_rsp->get_cur_app_val, p_pkt); + break; + + case AVRC_PDU_SET_PLAYER_APP_VALUE: + status = avrc_bld_set_app_setting_value_rsp(&p_rsp->set_app_val, p_pkt); + break; + + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: + status = avrc_bld_get_app_setting_attr_text_rsp(&p_rsp->get_app_attr_txt, p_pkt); + break; + + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: + status = avrc_bld_get_app_setting_value_text_rsp(&p_rsp->get_app_val_txt, p_pkt); + break; + + case AVRC_PDU_INFORM_DISPLAY_CHARSET: + status = avrc_bld_inform_charset_rsp(&p_rsp->inform_charset, p_pkt); + break; + + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: + status = avrc_bld_inform_battery_status_rsp(&p_rsp->inform_battery_status, p_pkt); + break; + + case AVRC_PDU_GET_ELEMENT_ATTR: + status = avrc_bld_get_elem_attrs_rsp(&p_rsp->get_elem_attrs, p_pkt); + break; + + case AVRC_PDU_GET_PLAY_STATUS: + status = avrc_bld_get_play_status_rsp(&p_rsp->get_play_status, p_pkt); + break; + + case AVRC_PDU_REGISTER_NOTIFICATION: + status = avrc_bld_notify_rsp(&p_rsp->reg_notif, p_pkt); + break; + + case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ + status = avrc_bld_next_rsp(&p_rsp->continu, p_pkt); + break; + + case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ + status = avrc_bld_next_rsp(&p_rsp->abort, p_pkt); + break; + } + + if (alloc && (status != AVRC_STS_NO_ERROR) ) + { + GKI_freebuf(p_pkt); + *pp_pkt = NULL; + } + AVRC_TRACE_API1("AVRC_BldResponse: returning %d", status); + return status; +} + +#endif /* (AVRC_METADATA_INCLUDED == TRUE)*/ + diff --git a/stack/avrc/avrc_int.h b/stack/avrc/avrc_int.h index b6c90b187..33eebdc46 100644..100755 --- a/stack/avrc/avrc_int.h +++ b/stack/avrc/avrc_int.h @@ -96,10 +96,31 @@ ** Type definitions *****************************************************************************/ +#if (AVRC_METADATA_INCLUDED == TRUE) +/* type for Metadata fragmentation control block */ +typedef struct +{ + BT_HDR *p_fmsg; /* the fragmented message */ + UINT8 frag_pdu; /* the PDU ID for fragmentation */ + BOOLEAN frag_enabled; /* fragmentation flag */ +} tAVRC_FRAG_CB; + +/* type for Metadata re-assembly control block */ +typedef struct +{ + BT_HDR *p_rmsg; /* the received message */ + UINT16 rasm_offset; /* re-assembly flag, the offset of the start fragment */ + UINT8 rasm_pdu; /* the PDU ID for re-assembly */ +} tAVRC_RASM_CB; +#endif typedef struct { tAVRC_CONN_CB ccb[AVCT_NUM_CONN]; +#if (AVRC_METADATA_INCLUDED == TRUE) + tAVRC_FRAG_CB fcb[AVCT_NUM_CONN]; + tAVRC_RASM_CB rcb[AVCT_NUM_CONN]; +#endif tAVRC_FIND_CBACK *p_cback; /* pointer to application callback */ tSDP_DISCOVERY_DB *p_db; /* pointer to discovery database */ UINT16 service_uuid; /* service UUID to search */ diff --git a/stack/avrc/avrc_opt.c b/stack/avrc/avrc_opt.c index 208a6c223..ff791557a 100644..100755 --- a/stack/avrc/avrc_opt.c +++ b/stack/avrc/avrc_opt.c @@ -18,7 +18,7 @@ /****************************************************************************** * - * nterface to AVRCP optional commands + * Interface to AVRCP optional commands * ******************************************************************************/ #include <string.h> @@ -53,8 +53,13 @@ static BT_HDR * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) WC_ASSERT(p_msg != NULL); +#if AVRC_METADATA_INCLUDED == TRUE + WC_ASSERT(AVRC_META_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); + if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_META_CMD_POOL_ID)) != NULL) +#else WC_ASSERT(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) +#endif { p_cmd->offset = AVCT_MSG_OFFSET; p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; diff --git a/stack/avrc/avrc_pars_tg.c b/stack/avrc/avrc_pars_tg.c new file mode 100755 index 000000000..0d9cf3477 --- /dev/null +++ b/stack/avrc/avrc_pars_tg.c @@ -0,0 +1,305 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2013 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. + * + ******************************************************************************/ +#include <string.h> + +#include "gki.h" +#include "avrc_api.h" +#include "avrc_defs.h" +#include "avrc_int.h" + +/***************************************************************************** +** Global data +*****************************************************************************/ +#if (AVRC_METADATA_INCLUDED == TRUE) + +/******************************************************************************* +** +** Function avrc_pars_vendor_cmd +** +** Description This function parses the vendor specific commands defined by +** Bluetooth SIG +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +static tAVRC_STS avrc_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAND *p_result, + UINT8 *p_buf, UINT16 buf_len) +{ + tAVRC_STS status = AVRC_STS_NO_ERROR; + UINT8 *p = p_msg->p_vendor_data; + UINT16 len; + UINT8 xx, yy; + UINT8 *p_u8; + UINT16 *p_u16; + UINT32 u32, u32_2, *p_u32; + tAVRC_APP_SETTING *p_app_set; + UINT16 size_needed; + + p_result->pdu = *p++; + AVRC_TRACE_DEBUG1("avrc_pars_vendor_cmd() pdu:0x%x", p_result->pdu); + if (!AVRC_IsValidAvcType (p_result->pdu, p_msg->hdr.ctype)) + { + AVRC_TRACE_DEBUG0("avrc_pars_vendor_cmd() detects wrong AV/C type!"); + status = AVRC_STS_BAD_CMD; + } + + p++; /* skip the reserved byte */ + BE_STREAM_TO_UINT16 (len, p); + if ((len+4) != (p_msg->vendor_len)) + { + status = AVRC_STS_INTERNAL_ERR; + } + + if (status != AVRC_STS_NO_ERROR) + return status; + + switch (p_result->pdu) + { + case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ + p_result->get_caps.capability_id = *p++; + if (!AVRC_IS_VALID_CAP_ID(p_result->get_caps.capability_id)) + status = AVRC_STS_BAD_PARAM; + else if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ + /* no additional parameters */ + if (len != 0) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ + p_result->list_app_values.attr_id = *p++; + if (!AVRC_IS_VALID_ATTRIBUTE(p_result->list_app_values.attr_id)) + status = AVRC_STS_BAD_PARAM; + else if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ + BE_STREAM_TO_UINT8 (p_result->get_cur_app_val.num_attr, p); + if (len != (p_result->get_cur_app_val.num_attr+1)) + { + status = AVRC_STS_INTERNAL_ERR; + break; + } + p_u8 = p_result->get_cur_app_val.attrs; + for (xx=0, yy=0; xx< p_result->get_cur_app_val.num_attr; xx++) + { + /* only report the valid player app attributes */ + if (AVRC_IsValidPlayerAttr(*p)) + p_u8[yy++] = *p; + p++; + } + p_result->get_cur_app_val.num_attr = yy; + if (yy == 0) + { + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ + BE_STREAM_TO_UINT8 (p_result->set_app_val.num_val, p); + size_needed = sizeof(tAVRC_APP_SETTING); + if (p_buf && (len == ((p_result->set_app_val.num_val<<1) + 1))) + { + p_result->set_app_val.p_vals = (tAVRC_APP_SETTING *)p_buf; + p_app_set = p_result->set_app_val.p_vals; + for (xx=0; ((xx< p_result->set_app_val.num_val) && (buf_len > size_needed)); xx++) + { + p_app_set[xx].attr_id = *p++; + p_app_set[xx].attr_val = *p++; + if (!avrc_is_valid_player_attrib_value(p_app_set[xx].attr_id, p_app_set[xx].attr_val)) + status = AVRC_STS_BAD_PARAM; + } + if (xx != p_result->set_app_val.num_val) + { + AVRC_TRACE_ERROR2("AVRC_PDU_SET_PLAYER_APP_VALUE not enough room:%d orig num_val:%d", + xx, p_result->set_app_val.num_val); + p_result->set_app_val.num_val = xx; + } + } + else + { + AVRC_TRACE_ERROR0("AVRC_PDU_SET_PLAYER_APP_VALUE NULL decode buffer or bad len"); + status = AVRC_STS_INTERNAL_ERR; + } + break; + + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:/* 0x16 */ + if (len < 3) + status = AVRC_STS_INTERNAL_ERR; + else + { + BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.attr_id, p); + if (!AVRC_IS_VALID_ATTRIBUTE(p_result->get_app_val_txt.attr_id)) + status = AVRC_STS_BAD_PARAM; + else + { + BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.num_val, p); + if ( (len - 2/* attr_id & num_val */) != p_result->get_app_val_txt.num_val) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_u8 = p_result->get_app_val_txt.vals; + for (xx=0; xx< p_result->get_app_val_txt.num_val; xx++) + { + p_u8[xx] = *p++; + if (!avrc_is_valid_player_attrib_value(p_result->get_app_val_txt.attr_id, + p_u8[xx])) + { + status = AVRC_STS_BAD_PARAM; + break; + } + } + } + } + } + break; + + case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ + if (len < 3) + status = AVRC_STS_INTERNAL_ERR; + else + { + BE_STREAM_TO_UINT8 (p_result->inform_charset.num_id, p); + if ( (len - 1/* num_id */) != p_result->inform_charset.num_id * 2) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_u16 = p_result->inform_charset.charsets; + if (p_result->inform_charset.num_id > AVRC_MAX_CHARSET_SIZE) + p_result->inform_charset.num_id = AVRC_MAX_CHARSET_SIZE; + for (xx=0; xx< p_result->inform_charset.num_id; xx++) + { + BE_STREAM_TO_UINT16 (p_u16[xx], p); + } + } + } + break; + + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:/* 0x18 */ + if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_result->inform_battery_status.battery_status = *p++; + if (!AVRC_IS_VALID_BATTERY_STATUS(p_result->inform_battery_status.battery_status)) + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ + if (len < 9) /* UID/8 and num_attr/1 */ + status = AVRC_STS_INTERNAL_ERR; + else + { + BE_STREAM_TO_UINT32 (u32, p); + BE_STREAM_TO_UINT32 (u32_2, p); + if (u32== 0 && u32_2 == 0) + { + BE_STREAM_TO_UINT8 (p_result->get_elem_attrs.num_attr, p); + if ( (len - 9/* UID/8 and num_attr/1 */) != (p_result->get_elem_attrs.num_attr * 4)) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_u32 = p_result->get_elem_attrs.attrs; + if (p_result->get_elem_attrs.num_attr > AVRC_MAX_ELEM_ATTR_SIZE) + p_result->get_elem_attrs.num_attr = AVRC_MAX_ELEM_ATTR_SIZE; + for (xx=0; xx< p_result->get_elem_attrs.num_attr; xx++) + { + BE_STREAM_TO_UINT32 (p_u32[xx], p); + } + } + } + else + status = AVRC_STS_NOT_FOUND; + } + break; + + case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ + /* no additional parameters */ + if (len != 0) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + if (len != 5) + status = AVRC_STS_INTERNAL_ERR; + BE_STREAM_TO_UINT8 (p_result->reg_notif.event_id, p); + BE_STREAM_TO_UINT32 (p_result->reg_notif.param, p); + break; + + /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */ + /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */ + + default: + status = AVRC_STS_BAD_CMD; + break; + } + + return status; +} + +/******************************************************************************* +** +** Function AVRC_ParsCommand +** +** Description This function is a superset of AVRC_ParsMetadata to parse the command. +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, UINT8 *p_buf, UINT16 buf_len) +{ + tAVRC_STS status = AVRC_STS_INTERNAL_ERR; + UINT16 id; + + if (p_msg && p_result) + { + switch (p_msg->hdr.opcode) + { + case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ + status = avrc_pars_vendor_cmd(&p_msg->vendor, p_result, p_buf, buf_len); + break; + + case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ + status = avrc_pars_pass_thru(&p_msg->pass, &id); + if (status == AVRC_STS_NO_ERROR) + { + p_result->pdu = (UINT8)id; + } + break; + + default: + AVRC_TRACE_ERROR1("AVRC_ParsCommand() unknown opcode:0x%x", p_msg->hdr.opcode); + break; + } + p_result->cmd.opcode = p_msg->hdr.opcode; + p_result->cmd.status = status; + } + AVRC_TRACE_DEBUG1("AVRC_ParsCommand() return status:0x%x", status); + return status; +} + +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ + diff --git a/stack/avrc/avrc_sdp.c b/stack/avrc/avrc_sdp.c index 427894c84..e447e48b6 100644..100755 --- a/stack/avrc/avrc_sdp.c +++ b/stack/avrc/avrc_sdp.c @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright (C) 2003-2012 Broadcom Corporation + * Copyright (C) 2003-2013 Broadcom Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,11 @@ tAVRC_CB avrc_cb; const tSDP_PROTOCOL_ELEM avrc_proto_list [] = { {UUID_PROTOCOL_L2CAP, 1, {AVCT_PSM, 0} }, +#if AVRC_METADATA_INCLUDED == TRUE + {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_2, 0} } +#else {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_0, 0} } +#endif }; @@ -212,7 +216,12 @@ UINT16 AVRC_AddRecord(UINT16 service_uuid, char *p_service_name, result &= SDP_AddProtocolList(sdp_handle, AVRC_NUM_PROTO_ELEMS, (tSDP_PROTOCOL_ELEM *)avrc_proto_list); /* add profile descriptor list */ +#if AVRC_METADATA_INCLUDED == TRUE + result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, AVRC_REV_1_3); +#else result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, AVRC_REV_1_0); +#endif + /* add supported categories */ p = temp; diff --git a/stack/avrc/avrc_utils.c b/stack/avrc/avrc_utils.c new file mode 100755 index 000000000..939a26f39 --- /dev/null +++ b/stack/avrc/avrc_utils.c @@ -0,0 +1,240 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2013 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. + * + ******************************************************************************/ +#include <string.h> + +#include "gki.h" +#include "avrc_api.h" +#include "avrc_int.h" + + +#if (AVRC_METADATA_INCLUDED == TRUE) + +/************************************************************************** +** +** Function AVRC_IsValidAvcType +** +** Description Check if correct AVC type is specified +** +** Returns returns TRUE if it is valid +** +** +*******************************************************************************/ +BOOLEAN AVRC_IsValidAvcType(UINT8 pdu_id, UINT8 avc_type) +{ + BOOLEAN result=FALSE; + + if (avc_type < AVRC_RSP_NOT_IMPL) /* command msg */ + { + switch (pdu_id) + { + case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ + case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ + case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: /* 0x16 */ + case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ + case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ + if (avc_type == AVRC_CMD_STATUS) + result=TRUE; + break; + + case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ + case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: /* 0x18 */ + case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ + case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ + if (avc_type == AVRC_CMD_CTRL) + result=TRUE; + break; + + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + if (avc_type == AVRC_CMD_NOTIF) + result=TRUE; + break; + } + } + else /* response msg */ + { + if (avc_type >= AVRC_RSP_NOT_IMPL && + avc_type <= AVRC_RSP_INTERIM ) + result=TRUE; + } + + return result; +} + +/******************************************************************************* +** +** Function avrc_is_valid_player_attrib_value +** +** Description Check if the given attrib value is valid for its attribute +** +** Returns returns TRUE if it is valid +** +*******************************************************************************/ +BOOLEAN avrc_is_valid_player_attrib_value(UINT8 attrib, UINT8 value) +{ + BOOLEAN result=FALSE; + + switch(attrib) + { + case AVRC_PLAYER_SETTING_EQUALIZER: + if ((value > 0) && + (value <= AVRC_PLAYER_VAL_ON)) + result=TRUE; + break; + + case AVRC_PLAYER_SETTING_REPEAT: + if ((value > 0) && + (value <= AVRC_PLAYER_VAL_GROUP_REPEAT)) + result=TRUE; + break; + + case AVRC_PLAYER_SETTING_SHUFFLE: + case AVRC_PLAYER_SETTING_SCAN: + if ((value > 0) && + (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE)) + result=TRUE; + break; + } + + if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && + attrib <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) + result = TRUE; + + if (!result) + AVRC_TRACE_ERROR2( + "avrc_is_valid_player_attrib_value() found not matching attrib(x%x)-value(x%x) pair!", + attrib, value); + + return result; +} + +/******************************************************************************* +** +** Function AVRC_IsValidPlayerAttr +** +** Description Check if the given attrib value is a valid one +** +** Returns returns TRUE if it is valid +** +*******************************************************************************/ +BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr) +{ + BOOLEAN result=FALSE; + + if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) || + (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && attr <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) ) + { + result = TRUE; + } + + return result; +} + + + +/******************************************************************************* +** +** Function avrc_pars_pass_thru +** +** Description This function parses the pass thru commands defined by +** Bluetooth SIG +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id) +{ + UINT8 *p_data; + UINT32 co_id; + UINT16 id; + tAVRC_STS status = AVRC_STS_BAD_CMD; + + if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN) + { + p_data = p_msg->p_pass_data; + AVRC_BE_STREAM_TO_CO_ID (co_id, p_data); + if (co_id == AVRC_CO_METADATA) + { + BE_STREAM_TO_UINT16 (id, p_data); + if (AVRC_IS_VALID_GROUP(id)) + { + *p_vendor_unique_id = id; + status = AVRC_STS_NO_ERROR; + } + } + } + return status; +} + +/******************************************************************************* +** +** Function avrc_opcode_from_pdu +** +** Description This function returns the opcode of the given pdu +** +** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE +** +*******************************************************************************/ +UINT8 avrc_opcode_from_pdu(UINT8 pdu) +{ + UINT8 opcode = 0; + + switch (pdu) + { + case AVRC_PDU_NEXT_GROUP: + case AVRC_PDU_PREV_GROUP: /* pass thru */ + opcode = AVRC_OP_PASS_THRU; + break; + + default: /* vendor */ + opcode = AVRC_OP_VENDOR; + break; + } + + return opcode; +} + +/******************************************************************************* +** +** Function avrc_is_valid_opcode +** +** Description This function returns the opcode of the given pdu +** +** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE +** +*******************************************************************************/ +BOOLEAN avrc_is_valid_opcode(UINT8 opcode) +{ + BOOLEAN is_valid = FALSE; + switch (opcode) + { + case AVRC_OP_BROWSE: + case AVRC_OP_PASS_THRU: + case AVRC_OP_VENDOR: + is_valid = TRUE; + break; + } + return is_valid; +} + +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ + |