2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /*****************************************************************************
21 * Description: Bluetooth AVRC implementation
23 *****************************************************************************/
25 #define LOG_TAG "bt_btif_avrc"
34 #include <hardware/bluetooth.h>
35 #include <hardware/bt_rc.h>
37 #include "avrc_defs.h"
39 #include "bta_av_api.h"
41 #include "btif_common.h"
42 #include "btif_util.h"
43 #include "bt_common.h"
44 #include "device/include/interop.h"
46 #include "osi/include/list.h"
47 #include "osi/include/properties.h"
49 #define RC_INVALID_TRACK_ID (0xFFFFFFFFFFFFFFFFULL)
50 /*****************************************************************************
52 ******************************************************************************/
54 /* cod value for Headsets */
55 #define COD_AV_HEADSETS 0x0404
56 /* for AVRC 1.4 need to change this */
57 #define MAX_RC_NOTIFICATIONS AVRC_EVT_VOLUME_CHANGE
59 #define IDX_GET_PLAY_STATUS_RSP 0
60 #define IDX_LIST_APP_ATTR_RSP 1
61 #define IDX_LIST_APP_VALUE_RSP 2
62 #define IDX_GET_CURR_APP_VAL_RSP 3
63 #define IDX_SET_APP_VAL_RSP 4
64 #define IDX_GET_APP_ATTR_TXT_RSP 5
65 #define IDX_GET_APP_VAL_TXT_RSP 6
66 #define IDX_GET_ELEMENT_ATTR_RSP 7
67 #define MAX_VOLUME 128
69 #define MAX_TRANSACTIONS_PER_SESSION 16
70 #define MAX_CMD_QUEUE_LEN 8
71 #define PLAY_STATUS_PLAYING 1
73 #define CHECK_RC_CONNECTED \
74 BTIF_TRACE_DEBUG("## %s ##", __FUNCTION__); \
75 if (btif_rc_cb.rc_connected == FALSE) \
77 BTIF_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
78 return BT_STATUS_NOT_READY; \
81 #define FILL_PDU_QUEUE(index, ctype, label, pending) \
83 btif_rc_cb.rc_pdu_info[index].ctype = ctype; \
84 btif_rc_cb.rc_pdu_info[index].label = label; \
85 btif_rc_cb.rc_pdu_info[index].is_rsp_pending = pending; \
88 #define SEND_METAMSG_RSP(index, avrc_rsp) \
90 if (btif_rc_cb.rc_pdu_info[index].is_rsp_pending == FALSE) \
92 BTIF_TRACE_WARNING("%s Not sending response as no PDU was registered", __FUNCTION__); \
93 return BT_STATUS_UNHANDLED; \
95 send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_pdu_info[index].label, \
96 btif_rc_cb.rc_pdu_info[index].ctype, avrc_rsp); \
97 btif_rc_cb.rc_pdu_info[index].ctype = 0; \
98 btif_rc_cb.rc_pdu_info[index].label = 0; \
99 btif_rc_cb.rc_pdu_info[index].is_rsp_pending = FALSE; \
102 /*****************************************************************************
103 ** Local type definitions
104 ******************************************************************************/
108 } btif_rc_reg_notifications_t;
114 BOOLEAN is_rsp_pending;
115 } btif_rc_cmd_ctxt_t;
117 /* 2 second timeout to get interim response */
118 #define BTIF_TIMEOUT_RC_INTERIM_RSP_MS (2 * 1000)
119 #define BTIF_TIMEOUT_RC_STATUS_CMD_MS (2 * 1000)
120 #define BTIF_TIMEOUT_RC_CONTROL_CMD_MS (2 * 1000)
128 } btif_rc_nfn_reg_status_t;
133 btif_rc_nfn_reg_status_t status;
134 } btif_rc_supported_event_t;
136 #define BTIF_RC_STS_TIMEOUT 0xFE
140 } btif_rc_status_cmd_timer_t;
145 } btif_rc_control_cmd_timer_t;
149 btif_rc_status_cmd_timer_t rc_status_cmd;
150 btif_rc_control_cmd_timer_t rc_control_cmd;
152 } btif_rc_timer_context_t;
155 BOOLEAN query_started;
160 UINT8 ext_attr_index;
162 btrc_player_app_attr_t attrs[AVRC_MAX_APP_ATTR_SIZE];
163 btrc_player_app_ext_attr_t ext_attrs[AVRC_MAX_APP_ATTR_SIZE];
164 } btif_rc_player_app_settings_t;
166 /* TODO : Merge btif_rc_reg_notifications_t and btif_rc_cmd_ctxt_t to a single struct */
168 BOOLEAN rc_connected;
170 tBTA_AV_FEAT rc_features;
172 UINT16 rc_pending_play;
173 btif_rc_cmd_ctxt_t rc_pdu_info[MAX_CMD_QUEUE_LEN];
174 btif_rc_reg_notifications_t rc_notif[MAX_RC_NOTIFICATIONS];
175 unsigned int rc_volume;
176 uint8_t rc_vol_label;
177 list_t *rc_supported_event_list;
178 btif_rc_player_app_settings_t rc_app_settings;
179 alarm_t *rc_play_status_timer;
180 BOOLEAN rc_features_processed;
181 UINT64 rc_playing_uid;
182 BOOLEAN rc_procedure_complete;
189 btif_rc_timer_context_t txn_timer_context;
195 pthread_mutex_t lbllock;
196 rc_transaction_t transaction[MAX_TRANSACTIONS_PER_SESSION];
201 #define MAX_UINPUT_PATHS 3
202 static const char* uinput_dev_path[] =
203 {"/dev/uinput", "/dev/input/uinput", "/dev/misc/uinput" };
204 static int uinput_fd = -1;
206 static int send_event (int fd, uint16_t type, uint16_t code, int32_t value);
207 static void send_key (int fd, uint16_t key, int pressed);
208 static int uinput_driver_check();
209 static int uinput_create(char *name);
210 static int init_uinput (void);
211 static void close_uinput (void);
212 static void sleep_ms(period_ms_t timeout_ms);
214 static const struct {
218 uint8_t release_quirk;
220 { "PLAY", AVRC_ID_PLAY, KEY_PLAYCD, 1 },
221 { "STOP", AVRC_ID_STOP, KEY_STOPCD, 0 },
222 { "PAUSE", AVRC_ID_PAUSE, KEY_PAUSECD, 1 },
223 { "FORWARD", AVRC_ID_FORWARD, KEY_NEXTSONG, 0 },
224 { "BACKWARD", AVRC_ID_BACKWARD, KEY_PREVIOUSSONG, 0 },
225 { "REWIND", AVRC_ID_REWIND, KEY_REWIND, 0 },
226 { "FAST FORWARD", AVRC_ID_FAST_FOR, KEY_FAST_FORWARD, 0 },
230 static void send_reject_response (UINT8 rc_handle, UINT8 label,
231 UINT8 pdu, UINT8 status);
232 static UINT8 opcode_from_pdu(UINT8 pdu);
233 static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label,
234 tBTA_AV_CODE code, tAVRC_RESPONSE *pmetamsg_resp);
235 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
236 static void register_volumechange(UINT8 label);
238 static void lbl_init();
239 static void lbl_destroy();
240 static void init_all_transactions();
241 static bt_status_t get_transaction(rc_transaction_t **ptransaction);
242 static void release_transaction(UINT8 label);
243 static rc_transaction_t* get_transaction_by_lbl(UINT8 label);
244 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
245 static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg);
247 #if (AVRC_CTLR_INCLUDED == TRUE)
248 static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG *pmeta_msg);
249 static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg);
250 static void btif_rc_ctrl_upstreams_rsp_cmd(
251 UINT8 event, tAVRC_COMMAND *pavrc_cmd, UINT8 label);
252 static void rc_ctrl_procedure_complete();
253 static void rc_stop_play_status_timer();
254 static void register_for_event_notification (btif_rc_supported_event_t *p_event);
255 static void handle_get_capability_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CAPS_RSP *p_rsp);
256 static void handle_app_attr_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_ATTR_RSP *p_rsp);
257 static void handle_app_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_VALUES_RSP *p_rsp);
258 static void handle_app_cur_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp);
259 static void handle_app_attr_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp);
260 static void handle_app_attr_val_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp);
261 static void handle_get_playstatus_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_PLAY_STATUS_RSP *p_rsp);
262 static void handle_get_elem_attr_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_ELEM_ATTRS_RSP *p_rsp);
263 static void handle_set_app_attr_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_RSP *p_rsp);
264 static bt_status_t get_play_status_cmd(void);
265 static bt_status_t get_player_app_setting_attr_text_cmd (UINT8 *attrs, UINT8 num_attrs);
266 static bt_status_t get_player_app_setting_value_text_cmd (UINT8 *vals, UINT8 num_vals);
267 static bt_status_t register_notification_cmd (UINT8 label, UINT8 event_id, UINT32 event_value);
268 static bt_status_t get_element_attribute_cmd (uint8_t num_attribute, uint32_t *p_attr_ids);
269 static bt_status_t getcapabilities_cmd (uint8_t cap_id);
270 static bt_status_t list_player_app_setting_attrib_cmd(void);
271 static bt_status_t list_player_app_setting_value_cmd(uint8_t attrib_id);
272 static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib, uint8_t* attrib_ids);
274 static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND* p_param, UINT8 ctype, UINT8 label);
275 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
276 static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label);
278 static void rc_start_play_status_timer(void);
279 static bool absolute_volume_disabled(void);
281 /*****************************************************************************
283 ******************************************************************************/
284 static btif_rc_cb_t btif_rc_cb;
285 static btrc_callbacks_t *bt_rc_callbacks = NULL;
286 static btrc_ctrl_callbacks_t *bt_rc_ctrl_callbacks = NULL;
288 /*****************************************************************************
290 ******************************************************************************/
292 /*****************************************************************************
294 ******************************************************************************/
295 extern BOOLEAN btif_hf_call_terminated_recently();
296 extern BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod);
298 extern fixed_queue_t *btu_general_alarm_queue;
300 /*****************************************************************************
302 ******************************************************************************/
304 /*****************************************************************************
305 ** Local uinput helper functions
306 ******************************************************************************/
307 int send_event (int fd, uint16_t type, uint16_t code, int32_t value)
309 struct uinput_event event;
310 BTIF_TRACE_DEBUG("%s type:%u code:%u value:%d", __FUNCTION__,
312 memset(&event, 0, sizeof(event));
317 return write(fd, &event, sizeof(event));
320 void send_key (int fd, uint16_t key, int pressed)
322 BTIF_TRACE_DEBUG("%s fd:%d key:%u pressed:%d", __FUNCTION__,
330 BTIF_TRACE_DEBUG("AVRCP: Send key %d (%d) fd=%d", key, pressed, fd);
331 send_event(fd, EV_KEY, key, pressed);
332 send_event(fd, EV_SYN, SYN_REPORT, 0);
335 /************** uinput related functions **************/
336 int uinput_driver_check()
339 for (i=0; i < MAX_UINPUT_PATHS; i++)
341 if (access(uinput_dev_path[i], O_RDWR) == 0) {
345 BTIF_TRACE_ERROR("%s ERROR: uinput device is not in the system", __FUNCTION__);
349 int uinput_create(char *name)
351 struct uinput_dev dev;
354 for(x=0; x < MAX_UINPUT_PATHS; x++)
356 fd = open(uinput_dev_path[x], O_RDWR);
361 if (x == MAX_UINPUT_PATHS) {
362 BTIF_TRACE_ERROR("%s ERROR: uinput device open failed", __FUNCTION__);
365 memset(&dev, 0, sizeof(dev));
367 strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE-1);
369 dev.id.bustype = BUS_BLUETOOTH;
370 dev.id.vendor = 0x0000;
371 dev.id.product = 0x0000;
372 dev.id.version = 0x0000;
374 if (write(fd, &dev, sizeof(dev)) < 0) {
375 BTIF_TRACE_ERROR("%s Unable to write device information", __FUNCTION__);
380 ioctl(fd, UI_SET_EVBIT, EV_KEY);
381 ioctl(fd, UI_SET_EVBIT, EV_REL);
382 ioctl(fd, UI_SET_EVBIT, EV_SYN);
384 for (x = 0; key_map[x].name != NULL; x++)
385 ioctl(fd, UI_SET_KEYBIT, key_map[x].mapped_id);
387 if (ioctl(fd, UI_DEV_CREATE, NULL) < 0) {
388 BTIF_TRACE_ERROR("%s Unable to create uinput device", __FUNCTION__);
395 int init_uinput (void)
397 char *name = "AVRCP";
399 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
400 uinput_fd = uinput_create(name);
402 BTIF_TRACE_ERROR("%s AVRCP: Failed to initialize uinput for %s (%d)",
403 __FUNCTION__, name, uinput_fd);
405 BTIF_TRACE_DEBUG("%s AVRCP: Initialized uinput for %s (fd=%d)",
406 __FUNCTION__, name, uinput_fd);
411 void close_uinput (void)
413 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
415 ioctl(uinput_fd, UI_DEV_DESTROY);
422 #if (AVRC_CTLR_INCLUDED == TRUE)
423 void rc_cleanup_sent_cmd (void *p_data)
425 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
429 void handle_rc_ctrl_features(BD_ADDR bd_addr)
431 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)||
432 ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCCT)&&
433 (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL)))
437 bdcpy(rc_addr.address,bd_addr);
439 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL)&&
440 (btif_rc_cb.rc_features & BTA_AV_FEAT_RCCT))
442 rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME;
444 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_METADATA)&&
445 (btif_rc_cb.rc_features & BTA_AV_FEAT_VENDOR)&&
446 (btif_rc_cb.rc_features_processed != TRUE))
448 rc_features |= BTRC_FEAT_METADATA;
449 /* Mark rc features processed to avoid repeating
450 * the AVRCP procedure every time on receiving this
453 btif_rc_cb.rc_features_processed = TRUE;
454 getcapabilities_cmd (AVRC_CAP_COMPANY_ID);
456 BTIF_TRACE_DEBUG("%s Update rc features to CTRL %d", __FUNCTION__, rc_features);
457 HAL_CBACK(bt_rc_ctrl_callbacks, getrcfeatures_cb, &rc_addr, rc_features);
462 void handle_rc_features(BD_ADDR bd_addr)
464 if (bt_rc_callbacks != NULL)
466 btrc_remote_features_t rc_features = BTRC_FEAT_NONE;
468 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
470 if (interop_match(INTEROP_DISABLE_ABSOLUTE_VOLUME, &rc_addr)
471 || absolute_volume_disabled())
472 btif_rc_cb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
474 if (btif_rc_cb.rc_features & BTA_AV_FEAT_BROWSE)
476 rc_features |= BTRC_FEAT_BROWSE;
479 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
480 if ( (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL) &&
481 (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG))
483 rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME;
487 if (btif_rc_cb.rc_features & BTA_AV_FEAT_METADATA)
489 rc_features |= BTRC_FEAT_METADATA;
492 BTIF_TRACE_DEBUG("%s: rc_features=0x%x", __FUNCTION__, rc_features);
493 HAL_CBACK(bt_rc_callbacks, remote_features_cb, &rc_addr, rc_features)
495 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
496 BTIF_TRACE_DEBUG("%s Checking for feature flags in btif_rc_handler with label %d",
497 __FUNCTION__, btif_rc_cb.rc_vol_label);
498 // Register for volume change on connect
499 if (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL &&
500 btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
502 rc_transaction_t *p_transaction=NULL;
503 bt_status_t status = BT_STATUS_NOT_READY;
504 if (MAX_LABEL==btif_rc_cb.rc_vol_label)
506 status=get_transaction(&p_transaction);
510 p_transaction=get_transaction_by_lbl(btif_rc_cb.rc_vol_label);
511 if (NULL!=p_transaction)
513 BTIF_TRACE_DEBUG("%s register_volumechange already in progress for label %d",
514 __FUNCTION__, btif_rc_cb.rc_vol_label);
518 status=get_transaction(&p_transaction);
521 if (BT_STATUS_SUCCESS == status && NULL!=p_transaction)
523 btif_rc_cb.rc_vol_label=p_transaction->lbl;
524 register_volumechange(btif_rc_cb.rc_vol_label);
531 /***************************************************************************
532 * Function handle_rc_connect
534 * - Argument: tBTA_AV_RC_OPEN RC open data structure
536 * - Description: RC connection event handler
538 ***************************************************************************/
539 void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
541 BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle);
542 bt_status_t result = BT_STATUS_SUCCESS;
543 #if (AVRC_CTLR_INCLUDED == TRUE)
547 if (p_rc_open->status == BTA_AV_SUCCESS)
549 //check if already some RC is connected
550 if (btif_rc_cb.rc_connected)
552 BTIF_TRACE_ERROR("%s Got RC OPEN in connected state, Connected RC: %d \
553 and Current RC: %d", __FUNCTION__, btif_rc_cb.rc_handle,p_rc_open->rc_handle );
554 if ((btif_rc_cb.rc_handle != p_rc_open->rc_handle)
555 && (bdcmp(btif_rc_cb.rc_addr, p_rc_open->peer_addr)))
557 BTIF_TRACE_DEBUG("%s Got RC connected for some other handle", __FUNCTION__);
558 BTA_AvCloseRc(p_rc_open->rc_handle);
562 memcpy(btif_rc_cb.rc_addr, p_rc_open->peer_addr, sizeof(BD_ADDR));
563 btif_rc_cb.rc_features = p_rc_open->peer_features;
564 btif_rc_cb.rc_vol_label=MAX_LABEL;
565 btif_rc_cb.rc_volume=MAX_VOLUME;
567 btif_rc_cb.rc_connected = TRUE;
568 btif_rc_cb.rc_handle = p_rc_open->rc_handle;
570 /* on locally initiated connection we will get remote features as part of connect */
571 if (btif_rc_cb.rc_features != 0)
572 handle_rc_features(btif_rc_cb.rc_addr);
575 result = uinput_driver_check();
576 if (result == BT_STATUS_SUCCESS)
583 BTIF_TRACE_WARNING("%s Avrcp TG role not enabled, not initializing UInput",
586 BTIF_TRACE_DEBUG("%s handle_rc_connect features %d ",__FUNCTION__, btif_rc_cb.rc_features);
587 #if (AVRC_CTLR_INCLUDED == TRUE)
588 btif_rc_cb.rc_playing_uid = RC_INVALID_TRACK_ID;
589 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
590 if (bt_rc_ctrl_callbacks != NULL)
592 HAL_CBACK(bt_rc_ctrl_callbacks, connection_state_cb, TRUE, &rc_addr);
594 /* report connection state if remote device is AVRCP target */
595 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)||
596 ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCCT)&&
597 (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL)))
599 handle_rc_ctrl_features(btif_rc_cb.rc_addr);
605 BTIF_TRACE_ERROR("%s Connect failed with error code: %d",
606 __FUNCTION__, p_rc_open->status);
607 btif_rc_cb.rc_connected = FALSE;
611 /***************************************************************************
612 * Function handle_rc_disconnect
614 * - Argument: tBTA_AV_RC_CLOSE RC close data structure
616 * - Description: RC disconnection event handler
618 ***************************************************************************/
619 void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
621 #if (AVRC_CTLR_INCLUDED == TRUE)
623 tBTA_AV_FEAT features;
625 BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_close->rc_handle);
626 if ((p_rc_close->rc_handle != btif_rc_cb.rc_handle)
627 && (bdcmp(btif_rc_cb.rc_addr, p_rc_close->peer_addr)))
629 BTIF_TRACE_ERROR("Got disconnect of unknown device");
632 #if (AVRC_CTLR_INCLUDED == TRUE)
633 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
634 features = btif_rc_cb.rc_features;
635 /* Clean up AVRCP procedure flags */
636 memset(&btif_rc_cb.rc_app_settings, 0,
637 sizeof(btif_rc_player_app_settings_t));
638 btif_rc_cb.rc_features_processed = FALSE;
639 btif_rc_cb.rc_procedure_complete = FALSE;
640 rc_stop_play_status_timer();
641 /* Check and clear the notification event list */
642 if (btif_rc_cb.rc_supported_event_list != NULL)
644 list_clear(btif_rc_cb.rc_supported_event_list);
645 btif_rc_cb.rc_supported_event_list = NULL;
648 btif_rc_cb.rc_handle = 0;
649 btif_rc_cb.rc_connected = FALSE;
650 memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
651 memset(btif_rc_cb.rc_notif, 0, sizeof(btif_rc_cb.rc_notif));
653 btif_rc_cb.rc_features = 0;
654 btif_rc_cb.rc_vol_label=MAX_LABEL;
655 btif_rc_cb.rc_volume=MAX_VOLUME;
656 init_all_transactions();
657 if (bt_rc_callbacks != NULL)
663 BTIF_TRACE_WARNING("%s Avrcp TG role not enabled, not closing UInput", __FUNCTION__);
666 memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
667 #if (AVRC_CTLR_INCLUDED == TRUE)
668 /* report connection state if device is AVRCP target */
669 if (bt_rc_ctrl_callbacks != NULL)
671 HAL_CBACK(bt_rc_ctrl_callbacks, connection_state_cb, FALSE, &rc_addr);
676 /***************************************************************************
677 * Function handle_rc_passthrough_cmd
679 * - Argument: tBTA_AV_RC rc_id remote control command ID
680 * tBTA_AV_STATE key_state status of key press
682 * - Description: Remote control command handler
684 ***************************************************************************/
685 void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
690 BTIF_TRACE_DEBUG("%s: p_remote_cmd->rc_id=%d", __FUNCTION__, p_remote_cmd->rc_id);
692 /* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up this PLAY */
695 /* queue AVRC PLAY if GAVDTP Open notification to app is pending (2 second timer) */
696 if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY) && (!btif_av_is_connected()))
698 if (p_remote_cmd->key_state == AVRC_STATE_PRESS)
700 APPL_TRACE_WARNING("%s: AVDT not open, queuing the PLAY command", __FUNCTION__);
701 btif_rc_cb.rc_pending_play = TRUE;
706 if ((p_remote_cmd->rc_id == BTA_AV_RC_PAUSE) && (btif_rc_cb.rc_pending_play))
708 APPL_TRACE_WARNING("%s: Clear the pending PLAY on PAUSE received", __FUNCTION__);
709 btif_rc_cb.rc_pending_play = FALSE;
712 if ((p_remote_cmd->rc_id == BTA_AV_RC_VOL_UP)||(p_remote_cmd->rc_id == BTA_AV_RC_VOL_DOWN))
713 return; // this command is not to be sent to UINPUT, only needed for PTS
716 if ((p_remote_cmd->rc_id == BTA_AV_RC_STOP) && (!btif_av_stream_started_ready()))
718 APPL_TRACE_WARNING("%s: Stream suspended, ignore STOP cmd",__FUNCTION__);
722 if (p_remote_cmd->key_state == AVRC_STATE_RELEASE) {
730 /* If this is Play/Pause command (press or release) before processing, check the following
731 * a voice call has ended recently
732 * the remote device is not of type headset
733 * If the above conditions meet, drop the Play/Pause command
734 * This fix is to interop with certain carkits which sends an automatic PLAY or PAUSE
735 * commands right after call ends
737 if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY || p_remote_cmd->rc_id == BTA_AV_RC_PAUSE)&&
738 (btif_hf_call_terminated_recently() == TRUE) &&
739 (check_cod( (const bt_bdaddr_t*)&(btif_rc_cb.rc_addr), COD_AV_HEADSETS) != TRUE))
741 BTIF_TRACE_DEBUG("%s:Dropping the play/Pause command received right after call end cmd:%d",
742 __FUNCTION__,p_remote_cmd->rc_id);
746 if (p_remote_cmd->rc_id == BTA_AV_RC_FAST_FOR || p_remote_cmd->rc_id == BTA_AV_RC_REWIND) {
747 HAL_CBACK(bt_rc_callbacks, passthrough_cmd_cb, p_remote_cmd->rc_id, pressed);
751 for (i = 0; key_map[i].name != NULL; i++) {
752 if (p_remote_cmd->rc_id == key_map[i].avrcp) {
753 BTIF_TRACE_DEBUG("%s: %s %s", __FUNCTION__, key_map[i].name, status);
755 /* MusicPlayer uses a long_press_timeout of 1 second for PLAYPAUSE button
756 * and maps that to autoshuffle. So if for some reason release for PLAY/PAUSE
757 * comes 1 second after the press, the MediaPlayer UI goes into a bad state.
758 * The reason for the delay could be sniff mode exit or some AVDTP procedure etc.
759 * The fix is to generate a release right after the press and drown the 'actual'
762 if ((key_map[i].release_quirk == 1) && (pressed == 0))
764 BTIF_TRACE_DEBUG("%s: AVRC %s Release Faked earlier, drowned now",
765 __FUNCTION__, key_map[i].name);
768 send_key(uinput_fd, key_map[i].mapped_id, pressed);
769 if ((key_map[i].release_quirk == 1) && (pressed == 1))
772 BTIF_TRACE_DEBUG("%s: AVRC %s Release quirk enabled, send release now",
773 __FUNCTION__, key_map[i].name);
774 send_key(uinput_fd, key_map[i].mapped_id, 0);
780 if (key_map[i].name == NULL)
781 BTIF_TRACE_ERROR("%s AVRCP: unknown button 0x%02X %s", __FUNCTION__,
782 p_remote_cmd->rc_id, status);
785 /***************************************************************************
786 * Function handle_rc_passthrough_rsp
788 * - Argument: tBTA_AV_REMOTE_RSP passthrough command response
790 * - Description: Remote control passthrough response handler
792 ***************************************************************************/
793 void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
795 #if (AVRC_CTLR_INCLUDED == TRUE)
797 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
800 if (p_remote_rsp->key_state == AVRC_STATE_RELEASE)
811 BTIF_TRACE_DEBUG("%s: rc_id=%d status=%s", __FUNCTION__, p_remote_rsp->rc_id, status);
813 release_transaction(p_remote_rsp->label);
814 if (bt_rc_ctrl_callbacks != NULL) {
815 HAL_CBACK(bt_rc_ctrl_callbacks, passthrough_rsp_cb, p_remote_rsp->rc_id, key_state);
820 BTIF_TRACE_ERROR("%s DUT does not support AVRCP controller role", __FUNCTION__);
823 BTIF_TRACE_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
827 /***************************************************************************
828 * Function handle_rc_vendorunique_rsp
830 * - Argument: tBTA_AV_REMOTE_RSP command response
832 * - Description: Remote control vendor unique response handler
834 ***************************************************************************/
835 void handle_rc_vendorunique_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
837 #if (AVRC_CTLR_INCLUDED == TRUE)
840 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
843 if (p_remote_rsp->key_state == AVRC_STATE_RELEASE)
854 if (p_remote_rsp->len > 0)
856 if (p_remote_rsp->len >= AVRC_PASS_THRU_GROUP_LEN)
857 vendor_id = p_remote_rsp->p_data[AVRC_PASS_THRU_GROUP_LEN -1];
858 osi_free_and_reset((void **)&p_remote_rsp->p_data);
860 BTIF_TRACE_DEBUG("%s: vendor_id=%d status=%s", __FUNCTION__, vendor_id, status);
862 release_transaction(p_remote_rsp->label);
863 HAL_CBACK(bt_rc_ctrl_callbacks, groupnavigation_rsp_cb, vendor_id, key_state);
867 BTIF_TRACE_ERROR("%s Remote does not support AVRCP TG role", __FUNCTION__);
870 BTIF_TRACE_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
874 void handle_uid_changed_notification(tBTA_AV_META_MSG *pmeta_msg, tAVRC_COMMAND *pavrc_command)
876 tAVRC_RESPONSE avrc_rsp = {0};
877 avrc_rsp.rsp.pdu = pavrc_command->pdu;
878 avrc_rsp.rsp.status = AVRC_STS_NO_ERROR;
879 avrc_rsp.rsp.opcode = pavrc_command->cmd.opcode;
881 avrc_rsp.reg_notif.event_id = pavrc_command->reg_notif.event_id;
882 avrc_rsp.reg_notif.param.uid_counter = 0;
884 send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_INTERIM, &avrc_rsp);
885 send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_CHANGED, &avrc_rsp);
889 /***************************************************************************
890 * Function handle_rc_metamsg_cmd
892 * - Argument: tBTA_AV_VENDOR Structure containing the received
895 * - Description: Remote control metamsg command handler (AVRCP 1.3)
897 ***************************************************************************/
898 void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg)
900 /* Parse the metamsg command and pass it on to BTL-IFS */
901 UINT8 scratch_buf[512] = {0};
902 tAVRC_COMMAND avrc_command = {0};
905 BTIF_TRACE_EVENT("+ %s", __FUNCTION__);
907 if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR)
909 BTIF_TRACE_WARNING("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode);
912 if (pmeta_msg->len < 3)
914 BTIF_TRACE_WARNING("Invalid length.Opcode: 0x%x, len: 0x%x", pmeta_msg->p_msg->hdr.opcode,
919 if (pmeta_msg->code >= AVRC_RSP_NOT_IMPL)
921 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
923 rc_transaction_t *transaction=NULL;
924 transaction=get_transaction_by_lbl(pmeta_msg->label);
925 if (NULL!=transaction)
927 handle_rc_metamsg_rsp(pmeta_msg);
931 BTIF_TRACE_DEBUG("%s:Discard vendor dependent rsp. code: %d label:%d.",
932 __FUNCTION__, pmeta_msg->code, pmeta_msg->label);
938 BTIF_TRACE_DEBUG("%s:Received vendor dependent rsp. code: %d len: %d. Not processing it.",
939 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
945 status=AVRC_ParsCommand(pmeta_msg->p_msg, &avrc_command, scratch_buf, sizeof(scratch_buf));
946 BTIF_TRACE_DEBUG("%s Received vendor command.code,PDU and label: %d, %d,%d",
947 __FUNCTION__, pmeta_msg->code, avrc_command.cmd.pdu, pmeta_msg->label);
949 if (status != AVRC_STS_NO_ERROR)
952 BTIF_TRACE_WARNING("%s: Error in parsing received metamsg command. status: 0x%02x",
953 __FUNCTION__, status);
954 send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_command.pdu, status);
958 /* if RegisterNotification, add it to our registered queue */
960 if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION)
962 UINT8 event_id = avrc_command.reg_notif.event_id;
963 BTIF_TRACE_EVENT("%s:New register notification received.event_id:%s,label:0x%x,code:%x",
964 __FUNCTION__,dump_rc_notification_event_id(event_id), pmeta_msg->label,pmeta_msg->code);
965 btif_rc_cb.rc_notif[event_id-1].bNotify = TRUE;
966 btif_rc_cb.rc_notif[event_id-1].label = pmeta_msg->label;
968 if (event_id == AVRC_EVT_UIDS_CHANGE)
970 handle_uid_changed_notification(pmeta_msg, &avrc_command);
976 BTIF_TRACE_EVENT("%s: Passing received metamsg command to app. pdu: %s",
977 __FUNCTION__, dump_rc_pdu(avrc_command.cmd.pdu));
979 /* Since handle_rc_metamsg_cmd() itself is called from
980 *btif context, no context switching is required. Invoke
981 * btif_rc_upstreams_evt directly from here. */
982 btif_rc_upstreams_evt((uint16_t)avrc_command.cmd.pdu, &avrc_command, pmeta_msg->code,
987 /***************************************************************************
989 ** Function btif_rc_handler
991 ** Description RC event handler
993 ***************************************************************************/
994 void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
996 BTIF_TRACE_DEBUG ("%s event:%s", __FUNCTION__, dump_rc_event(event));
999 case BTA_AV_RC_OPEN_EVT:
1001 BTIF_TRACE_DEBUG("%s Peer_features:%x", __FUNCTION__, p_data->rc_open.peer_features);
1002 handle_rc_connect( &(p_data->rc_open) );
1005 case BTA_AV_RC_CLOSE_EVT:
1007 handle_rc_disconnect( &(p_data->rc_close) );
1010 case BTA_AV_REMOTE_CMD_EVT:
1012 if (bt_rc_callbacks != NULL)
1014 BTIF_TRACE_DEBUG("%s rc_id:0x%x key_state:%d",
1015 __FUNCTION__, p_data->remote_cmd.rc_id,
1016 p_data->remote_cmd.key_state);
1017 /** In race conditions just after 2nd AVRCP is connected
1018 * remote might send pass through commands, so check for
1019 * Rc handle before processing pass through commands
1021 if (btif_rc_cb.rc_handle == p_data->remote_cmd.rc_handle)
1023 handle_rc_passthrough_cmd( (&p_data->remote_cmd) );
1027 BTIF_TRACE_DEBUG("%s Pass-through command for Invalid rc handle", __FUNCTION__);
1032 BTIF_TRACE_ERROR("AVRCP TG role not up, drop passthrough commands");
1037 #if (AVRC_CTLR_INCLUDED == TRUE)
1038 case BTA_AV_REMOTE_RSP_EVT:
1040 BTIF_TRACE_DEBUG("%s RSP: rc_id:0x%x key_state:%d",
1041 __FUNCTION__, p_data->remote_rsp.rc_id, p_data->remote_rsp.key_state);
1042 if (p_data->remote_rsp.rc_id == AVRC_ID_VENDOR)
1044 handle_rc_vendorunique_rsp(&p_data->remote_rsp);
1048 handle_rc_passthrough_rsp(&p_data->remote_rsp);
1054 case BTA_AV_RC_FEAT_EVT:
1056 BTIF_TRACE_DEBUG("%s Peer_features:%x", __FUNCTION__, p_data->rc_feat.peer_features);
1057 btif_rc_cb.rc_features = p_data->rc_feat.peer_features;
1058 handle_rc_features(p_data->rc_feat.peer_addr);
1059 #if (AVRC_CTLR_INCLUDED == TRUE)
1060 if ((btif_rc_cb.rc_connected) && (bt_rc_ctrl_callbacks != NULL))
1062 handle_rc_ctrl_features(btif_rc_cb.rc_addr);
1068 case BTA_AV_META_MSG_EVT:
1070 if (bt_rc_callbacks != NULL)
1072 BTIF_TRACE_DEBUG("%s BTA_AV_META_MSG_EVT code:%d label:%d",
1074 p_data->meta_msg.code,
1075 p_data->meta_msg.label);
1076 BTIF_TRACE_DEBUG("%s company_id:0x%x len:%d handle:%d",
1078 p_data->meta_msg.company_id,
1079 p_data->meta_msg.len,
1080 p_data->meta_msg.rc_handle);
1081 /* handle the metamsg command */
1082 handle_rc_metamsg_cmd(&(p_data->meta_msg));
1083 /* Free the Memory allocated for tAVRC_MSG */
1085 #if (AVRC_CTLR_INCLUDED == TRUE)
1086 else if ((bt_rc_callbacks == NULL)&&(bt_rc_ctrl_callbacks != NULL))
1088 /* This is case of Sink + CT + TG(for abs vol)) */
1089 BTIF_TRACE_DEBUG("%s BTA_AV_META_MSG_EVT code:%d label:%d",
1091 p_data->meta_msg.code,
1092 p_data->meta_msg.label);
1093 BTIF_TRACE_DEBUG("%s company_id:0x%x len:%d handle:%d",
1095 p_data->meta_msg.company_id,
1096 p_data->meta_msg.len,
1097 p_data->meta_msg.rc_handle);
1098 if ((p_data->meta_msg.code >= AVRC_RSP_NOT_IMPL)&&
1099 (p_data->meta_msg.code <= AVRC_RSP_INTERIM))
1101 /* Its a response */
1102 handle_avk_rc_metamsg_rsp(&(p_data->meta_msg));
1104 else if (p_data->meta_msg.code <= AVRC_CMD_GEN_INQ)
1107 handle_avk_rc_metamsg_cmd(&(p_data->meta_msg));
1114 BTIF_TRACE_ERROR("Neither CTRL, nor TG is up, drop meta commands");
1120 BTIF_TRACE_DEBUG("%s Unhandled RC event : 0x%x", __FUNCTION__, event);
1124 /***************************************************************************
1126 ** Function btif_rc_get_connected_peer
1128 ** Description Fetches the connected headset's BD_ADDR if any
1130 ***************************************************************************/
1131 BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr)
1133 if (btif_rc_cb.rc_connected == TRUE) {
1134 bdcpy(peer_addr, btif_rc_cb.rc_addr);
1140 /***************************************************************************
1142 ** Function btif_rc_get_connected_peer_handle
1144 ** Description Fetches the connected headset's handle if any
1146 ***************************************************************************/
1147 UINT8 btif_rc_get_connected_peer_handle(void)
1149 return btif_rc_cb.rc_handle;
1152 /***************************************************************************
1154 ** Function btif_rc_check_handle_pending_play
1156 ** Description Clears the queued PLAY command. if bSend is TRUE, forwards to app
1158 ***************************************************************************/
1160 /* clear the queued PLAY command. if bSend is TRUE, forward to app */
1161 void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp)
1165 BTIF_TRACE_DEBUG("%s: bSendToApp=%d", __FUNCTION__, bSendToApp);
1166 if (btif_rc_cb.rc_pending_play)
1170 tBTA_AV_REMOTE_CMD remote_cmd;
1171 APPL_TRACE_DEBUG("%s: Sending queued PLAYED event to app", __FUNCTION__);
1173 memset (&remote_cmd, 0, sizeof(tBTA_AV_REMOTE_CMD));
1174 remote_cmd.rc_handle = btif_rc_cb.rc_handle;
1175 remote_cmd.rc_id = AVRC_ID_PLAY;
1176 remote_cmd.hdr.ctype = AVRC_CMD_CTRL;
1177 remote_cmd.hdr.opcode = AVRC_OP_PASS_THRU;
1179 /* delay sending to app, else there is a timing issue in the framework,
1180 ** which causes the audio to be on th device's speaker. Delay between
1184 /* send to app - both PRESSED & RELEASED */
1185 remote_cmd.key_state = AVRC_STATE_PRESS;
1186 handle_rc_passthrough_cmd( &remote_cmd );
1190 remote_cmd.key_state = AVRC_STATE_RELEASE;
1191 handle_rc_passthrough_cmd( &remote_cmd );
1193 btif_rc_cb.rc_pending_play = FALSE;
1197 /* Generic reject response */
1198 static void send_reject_response (UINT8 rc_handle, UINT8 label, UINT8 pdu, UINT8 status)
1200 UINT8 ctype = AVRC_RSP_REJ;
1201 tAVRC_RESPONSE avrc_rsp;
1202 BT_HDR *p_msg = NULL;
1203 memset (&avrc_rsp, 0, sizeof(tAVRC_RESPONSE));
1205 avrc_rsp.rsp.opcode = opcode_from_pdu(pdu);
1206 avrc_rsp.rsp.pdu = pdu;
1207 avrc_rsp.rsp.status = status;
1209 if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(rc_handle, &avrc_rsp, &p_msg)) )
1211 BTIF_TRACE_DEBUG("%s:Sending error notification to handle:%d. pdu:%s,status:0x%02x",
1212 __FUNCTION__, rc_handle, dump_rc_pdu(pdu), status);
1213 BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
1217 /***************************************************************************
1218 * Function send_metamsg_rsp
1221 * rc_handle RC handle corresponding to the connected RC
1222 * label Label of the RC response
1223 * code Response type
1224 * pmetamsg_resp Vendor response
1226 * - Description: Remote control metamsg response handler (AVRCP 1.3)
1228 ***************************************************************************/
1229 static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label, tBTA_AV_CODE code,
1230 tAVRC_RESPONSE *pmetamsg_resp)
1236 BTIF_TRACE_WARNING("%s: Invalid response received from application", __FUNCTION__);
1240 BTIF_TRACE_EVENT("+%s: rc_handle: %d, label: %d, code: 0x%02x, pdu: %s", __FUNCTION__,
1241 rc_handle, label, code, dump_rc_pdu(pmetamsg_resp->rsp.pdu));
1243 if (pmetamsg_resp->rsp.status != AVRC_STS_NO_ERROR)
1245 ctype = AVRC_RSP_REJ;
1249 if ( code < AVRC_RSP_NOT_IMPL)
1251 if (code == AVRC_CMD_NOTIF)
1253 ctype = AVRC_RSP_INTERIM;
1255 else if (code == AVRC_CMD_STATUS)
1257 ctype = AVRC_RSP_IMPL_STBL;
1261 ctype = AVRC_RSP_ACCEPT;
1269 /* if response is for register_notification, make sure the rc has
1270 actually registered for this */
1271 if ((pmetamsg_resp->rsp.pdu == AVRC_PDU_REGISTER_NOTIFICATION) && (code == AVRC_RSP_CHANGED))
1273 BOOLEAN bSent = FALSE;
1274 UINT8 event_id = pmetamsg_resp->reg_notif.event_id;
1275 BOOLEAN bNotify = (btif_rc_cb.rc_connected) && (btif_rc_cb.rc_notif[event_id-1].bNotify);
1277 /* de-register this notification for a CHANGED response */
1278 btif_rc_cb.rc_notif[event_id-1].bNotify = FALSE;
1279 BTIF_TRACE_DEBUG("%s rc_handle: %d. event_id: 0x%02d bNotify:%u", __FUNCTION__,
1280 btif_rc_cb.rc_handle, event_id, bNotify);
1283 BT_HDR *p_msg = NULL;
1286 if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(btif_rc_cb.rc_handle,
1287 pmetamsg_resp, &p_msg)) )
1289 BTIF_TRACE_DEBUG("%s Sending notification to rc_handle: %d. event_id: 0x%02d",
1290 __FUNCTION__, btif_rc_cb.rc_handle, event_id);
1292 BTA_AvMetaRsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
1297 BTIF_TRACE_WARNING("%s failed to build metamsg response. status: 0x%02x",
1298 __FUNCTION__, status);
1305 BTIF_TRACE_DEBUG("%s: Notification not sent, as there are no RC connections or the \
1306 CT has not subscribed for event_id: %s", __FUNCTION__, dump_rc_notification_event_id(event_id));
1311 /* All other commands go here */
1313 BT_HDR *p_msg = NULL;
1316 status = AVRC_BldResponse(rc_handle, pmetamsg_resp, &p_msg);
1318 if (status == AVRC_STS_NO_ERROR)
1320 BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
1324 BTIF_TRACE_ERROR("%s: failed to build metamsg response. status: 0x%02x",
1325 __FUNCTION__, status);
1330 static UINT8 opcode_from_pdu(UINT8 pdu)
1336 case AVRC_PDU_NEXT_GROUP:
1337 case AVRC_PDU_PREV_GROUP: /* pass thru */
1338 opcode = AVRC_OP_PASS_THRU;
1341 default: /* vendor */
1342 opcode = AVRC_OP_VENDOR;
1349 /*******************************************************************************
1351 ** Function btif_rc_upstreams_evt
1353 ** Description Executes AVRC UPSTREAMS events in btif context.
1357 *******************************************************************************/
1358 static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 ctype, UINT8 label)
1360 BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
1361 dump_rc_pdu(pavrc_cmd->pdu), btif_rc_cb.rc_handle, ctype, label);
1365 case AVRC_PDU_GET_PLAY_STATUS:
1367 FILL_PDU_QUEUE(IDX_GET_PLAY_STATUS_RSP, ctype, label, TRUE)
1368 HAL_CBACK(bt_rc_callbacks, get_play_status_cb);
1371 case AVRC_PDU_LIST_PLAYER_APP_ATTR:
1372 case AVRC_PDU_LIST_PLAYER_APP_VALUES:
1373 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
1374 case AVRC_PDU_SET_PLAYER_APP_VALUE:
1375 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
1376 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
1378 /* TODO: Add support for Application Settings */
1379 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_CMD);
1382 case AVRC_PDU_GET_ELEMENT_ATTR:
1384 btrc_media_attr_t element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
1386 memset(&element_attrs, 0, sizeof(element_attrs));
1387 if (pavrc_cmd->get_elem_attrs.num_attr == 0)
1389 /* CT requests for all attributes */
1391 num_attr = BTRC_MAX_ELEM_ATTR_SIZE;
1392 for (attr_cnt = 0; attr_cnt < BTRC_MAX_ELEM_ATTR_SIZE; attr_cnt++)
1394 element_attrs[attr_cnt] = attr_cnt + 1;
1397 else if (pavrc_cmd->get_elem_attrs.num_attr == 0xFF)
1399 /* 0xff indicates, no attributes requested - reject */
1400 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
1401 AVRC_STS_BAD_PARAM);
1406 int attr_cnt, filled_attr_count;
1409 /* Attribute IDs from 1 to AVRC_MAX_NUM_MEDIA_ATTR_ID are only valid,
1410 * hence HAL definition limits the attributes to AVRC_MAX_NUM_MEDIA_ATTR_ID.
1411 * Fill only valid entries.
1413 for (attr_cnt = 0; (attr_cnt < pavrc_cmd->get_elem_attrs.num_attr) &&
1414 (num_attr < AVRC_MAX_NUM_MEDIA_ATTR_ID); attr_cnt++)
1416 if ((pavrc_cmd->get_elem_attrs.attrs[attr_cnt] > 0) &&
1417 (pavrc_cmd->get_elem_attrs.attrs[attr_cnt] <= AVRC_MAX_NUM_MEDIA_ATTR_ID))
1419 /* Skip the duplicate entries : PTS sends duplicate entries for Fragment cases
1421 for (filled_attr_count = 0; filled_attr_count < num_attr; filled_attr_count++)
1423 if (element_attrs[filled_attr_count] == pavrc_cmd->get_elem_attrs.attrs[attr_cnt])
1426 if (filled_attr_count == num_attr)
1428 element_attrs[num_attr] = pavrc_cmd->get_elem_attrs.attrs[attr_cnt];
1434 FILL_PDU_QUEUE(IDX_GET_ELEMENT_ATTR_RSP, ctype, label, TRUE);
1435 HAL_CBACK(bt_rc_callbacks, get_element_attr_cb, num_attr, element_attrs);
1438 case AVRC_PDU_REGISTER_NOTIFICATION:
1440 if (pavrc_cmd->reg_notif.event_id == BTRC_EVT_PLAY_POS_CHANGED &&
1441 pavrc_cmd->reg_notif.param == 0)
1443 BTIF_TRACE_WARNING("%s Device registering position changed with illegal param 0.",
1445 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM);
1446 /* de-register this notification for a rejected response */
1447 btif_rc_cb.rc_notif[BTRC_EVT_PLAY_POS_CHANGED - 1].bNotify = FALSE;
1450 HAL_CBACK(bt_rc_callbacks, register_notification_cb, pavrc_cmd->reg_notif.event_id,
1451 pavrc_cmd->reg_notif.param);
1454 case AVRC_PDU_INFORM_DISPLAY_CHARSET:
1456 tAVRC_RESPONSE avrc_rsp;
1457 BTIF_TRACE_EVENT("%s() AVRC_PDU_INFORM_DISPLAY_CHARSET", __FUNCTION__);
1458 if (btif_rc_cb.rc_connected == TRUE)
1460 memset(&(avrc_rsp.inform_charset), 0, sizeof(tAVRC_RSP));
1461 avrc_rsp.inform_charset.opcode=opcode_from_pdu(AVRC_PDU_INFORM_DISPLAY_CHARSET);
1462 avrc_rsp.inform_charset.pdu=AVRC_PDU_INFORM_DISPLAY_CHARSET;
1463 avrc_rsp.inform_charset.status=AVRC_STS_NO_ERROR;
1464 send_metamsg_rsp(btif_rc_cb.rc_handle, label, ctype, &avrc_rsp);
1470 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
1471 (pavrc_cmd->pdu == AVRC_PDU_SEARCH)?AVRC_STS_SEARCH_NOT_SUP:AVRC_STS_BAD_CMD);
1478 #if (AVRC_CTLR_INCLUDED == TRUE)
1479 /*******************************************************************************
1481 ** Function btif_rc_ctrl_upstreams_rsp_cmd
1483 ** Description Executes AVRC UPSTREAMS response events in btif context.
1487 *******************************************************************************/
1488 static void btif_rc_ctrl_upstreams_rsp_cmd(UINT8 event, tAVRC_COMMAND *pavrc_cmd,
1491 BTIF_TRACE_DEBUG("%s pdu: %s handle: 0x%x", __FUNCTION__,
1492 dump_rc_pdu(pavrc_cmd->pdu), btif_rc_cb.rc_handle);
1493 bt_bdaddr_t rc_addr;
1494 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
1495 #if (AVRC_CTLR_INCLUDED == TRUE)
1498 case AVRC_PDU_SET_ABSOLUTE_VOLUME:
1499 HAL_CBACK(bt_rc_ctrl_callbacks,setabsvol_cmd_cb, &rc_addr,
1500 pavrc_cmd->volume.volume, label);
1502 case AVRC_PDU_REGISTER_NOTIFICATION:
1503 if (pavrc_cmd->reg_notif.event_id == AVRC_EVT_VOLUME_CHANGE)
1505 HAL_CBACK(bt_rc_ctrl_callbacks, registernotification_absvol_cb,
1514 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
1515 /*******************************************************************************
1517 ** Function btif_rc_upstreams_rsp_evt
1519 ** Description Executes AVRC UPSTREAMS response events in btif context.
1523 *******************************************************************************/
1524 static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label)
1526 BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
1527 dump_rc_pdu(pavrc_resp->pdu), btif_rc_cb.rc_handle, ctype, label);
1531 case AVRC_PDU_REGISTER_NOTIFICATION:
1533 if (AVRC_RSP_CHANGED==ctype)
1534 btif_rc_cb.rc_volume=pavrc_resp->reg_notif.param.volume;
1535 HAL_CBACK(bt_rc_callbacks, volume_change_cb, pavrc_resp->reg_notif.param.volume,ctype)
1539 case AVRC_PDU_SET_ABSOLUTE_VOLUME:
1541 BTIF_TRACE_DEBUG("%s Set absolute volume change event received: volume %d,ctype %d",
1542 __FUNCTION__, pavrc_resp->volume.volume,ctype);
1543 if (AVRC_RSP_ACCEPT==ctype)
1544 btif_rc_cb.rc_volume=pavrc_resp->volume.volume;
1545 HAL_CBACK(bt_rc_callbacks,volume_change_cb,pavrc_resp->volume.volume,ctype)
1555 /************************************************************************************
1556 ** AVRCP API Functions
1557 ************************************************************************************/
1559 /*******************************************************************************
1563 ** Description Initializes the AVRC interface
1565 ** Returns bt_status_t
1567 *******************************************************************************/
1568 static bt_status_t init(btrc_callbacks_t* callbacks )
1570 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
1571 bt_status_t result = BT_STATUS_SUCCESS;
1573 if (bt_rc_callbacks)
1574 return BT_STATUS_DONE;
1576 bt_rc_callbacks = callbacks;
1577 memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
1578 btif_rc_cb.rc_vol_label=MAX_LABEL;
1579 btif_rc_cb.rc_volume=MAX_VOLUME;
1585 /*******************************************************************************
1587 ** Function init_ctrl
1589 ** Description Initializes the AVRC interface
1591 ** Returns bt_status_t
1593 *******************************************************************************/
1594 static bt_status_t init_ctrl(btrc_ctrl_callbacks_t* callbacks )
1596 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
1597 bt_status_t result = BT_STATUS_SUCCESS;
1599 if (bt_rc_ctrl_callbacks)
1600 return BT_STATUS_DONE;
1602 bt_rc_ctrl_callbacks = callbacks;
1603 memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
1604 btif_rc_cb.rc_vol_label=MAX_LABEL;
1605 btif_rc_cb.rc_volume=MAX_VOLUME;
1611 static void rc_ctrl_procedure_complete ()
1613 if (btif_rc_cb.rc_procedure_complete == TRUE)
1617 btif_rc_cb.rc_procedure_complete = TRUE;
1618 UINT32 attr_list[] = {
1619 AVRC_MEDIA_ATTR_ID_TITLE,
1620 AVRC_MEDIA_ATTR_ID_ARTIST,
1621 AVRC_MEDIA_ATTR_ID_ALBUM,
1622 AVRC_MEDIA_ATTR_ID_TRACK_NUM,
1623 AVRC_MEDIA_ATTR_ID_NUM_TRACKS,
1624 AVRC_MEDIA_ATTR_ID_GENRE,
1625 AVRC_MEDIA_ATTR_ID_PLAYING_TIME
1627 get_element_attribute_cmd (AVRC_MAX_NUM_MEDIA_ATTR_ID, attr_list);
1630 /***************************************************************************
1632 ** Function get_play_status_rsp
1634 ** Description Returns the current play status.
1635 ** This method is called in response to
1636 ** GetPlayStatus request.
1638 ** Returns bt_status_t
1640 ***************************************************************************/
1641 static bt_status_t get_play_status_rsp(btrc_play_status_t play_status, uint32_t song_len,
1644 tAVRC_RESPONSE avrc_rsp;
1646 memset(&(avrc_rsp.get_play_status), 0, sizeof(tAVRC_GET_PLAY_STATUS_RSP));
1647 avrc_rsp.get_play_status.song_len = song_len;
1648 avrc_rsp.get_play_status.song_pos = song_pos;
1649 avrc_rsp.get_play_status.play_status = play_status;
1651 avrc_rsp.get_play_status.pdu = AVRC_PDU_GET_PLAY_STATUS;
1652 avrc_rsp.get_play_status.opcode = opcode_from_pdu(AVRC_PDU_GET_PLAY_STATUS);
1653 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1654 /* Send the response */
1655 SEND_METAMSG_RSP(IDX_GET_PLAY_STATUS_RSP, &avrc_rsp);
1656 return BT_STATUS_SUCCESS;
1659 /***************************************************************************
1661 ** Function get_element_attr_rsp
1663 ** Description Returns the current songs' element attributes
1666 ** Returns bt_status_t
1668 ***************************************************************************/
1669 static bt_status_t get_element_attr_rsp(uint8_t num_attr, btrc_element_attr_val_t *p_attrs)
1671 tAVRC_RESPONSE avrc_rsp;
1673 tAVRC_ATTR_ENTRY element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
1675 memset(element_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr);
1679 avrc_rsp.get_play_status.status = AVRC_STS_BAD_PARAM;
1683 for (i=0; i<num_attr; i++) {
1684 element_attrs[i].attr_id = p_attrs[i].attr_id;
1685 element_attrs[i].name.charset_id = AVRC_CHARSET_ID_UTF8;
1686 element_attrs[i].name.str_len = (UINT16)strlen((char *)p_attrs[i].text);
1687 element_attrs[i].name.p_str = p_attrs[i].text;
1688 BTIF_TRACE_DEBUG("%s attr_id:0x%x, charset_id:0x%x, str_len:%d, str:%s",
1689 __FUNCTION__, (unsigned int)element_attrs[i].attr_id,
1690 element_attrs[i].name.charset_id, element_attrs[i].name.str_len,
1691 element_attrs[i].name.p_str);
1693 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1695 avrc_rsp.get_elem_attrs.num_attr = num_attr;
1696 avrc_rsp.get_elem_attrs.p_attrs = element_attrs;
1697 avrc_rsp.get_elem_attrs.pdu = AVRC_PDU_GET_ELEMENT_ATTR;
1698 avrc_rsp.get_elem_attrs.opcode = opcode_from_pdu(AVRC_PDU_GET_ELEMENT_ATTR);
1699 /* Send the response */
1700 SEND_METAMSG_RSP(IDX_GET_ELEMENT_ATTR_RSP, &avrc_rsp);
1701 return BT_STATUS_SUCCESS;
1704 /***************************************************************************
1706 ** Function register_notification_rsp
1708 ** Description Response to the register notification request.
1711 ** Returns bt_status_t
1713 ***************************************************************************/
1714 static bt_status_t register_notification_rsp(btrc_event_id_t event_id,
1715 btrc_notification_type_t type, btrc_register_notification_t *p_param)
1717 tAVRC_RESPONSE avrc_rsp;
1719 BTIF_TRACE_EVENT("## %s ## event_id:%s", __FUNCTION__, dump_rc_notification_event_id(event_id));
1720 if (btif_rc_cb.rc_notif[event_id-1].bNotify == FALSE)
1722 BTIF_TRACE_ERROR("Avrcp Event id not registered: event_id = %x", event_id);
1723 return BT_STATUS_NOT_READY;
1725 memset(&(avrc_rsp.reg_notif), 0, sizeof(tAVRC_REG_NOTIF_RSP));
1726 avrc_rsp.reg_notif.event_id = event_id;
1730 case BTRC_EVT_PLAY_STATUS_CHANGED:
1731 avrc_rsp.reg_notif.param.play_status = p_param->play_status;
1732 if (avrc_rsp.reg_notif.param.play_status == PLAY_STATUS_PLAYING)
1733 btif_av_clear_remote_suspend_flag();
1735 case BTRC_EVT_TRACK_CHANGE:
1736 memcpy(&(avrc_rsp.reg_notif.param.track), &(p_param->track), sizeof(btrc_uid_t));
1738 case BTRC_EVT_PLAY_POS_CHANGED:
1739 avrc_rsp.reg_notif.param.play_pos = p_param->song_pos;
1742 BTIF_TRACE_WARNING("%s : Unhandled event ID : 0x%x", __FUNCTION__, event_id);
1743 return BT_STATUS_UNHANDLED;
1746 avrc_rsp.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
1747 avrc_rsp.reg_notif.opcode = opcode_from_pdu(AVRC_PDU_REGISTER_NOTIFICATION);
1748 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1750 /* Send the response. */
1751 send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
1752 ((type == BTRC_NOTIFICATION_TYPE_INTERIM)?AVRC_CMD_NOTIF:AVRC_RSP_CHANGED), &avrc_rsp);
1753 return BT_STATUS_SUCCESS;
1756 /***************************************************************************
1758 ** Function set_volume
1760 ** Description Send current volume setting to remote side.
1761 ** Support limited to SetAbsoluteVolume
1762 ** This can be enhanced to support Relative Volume (AVRCP 1.0).
1763 ** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN
1764 ** as opposed to absolute volume level
1765 ** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
1767 ** Returns bt_status_t
1769 ***************************************************************************/
1770 static bt_status_t set_volume(uint8_t volume)
1772 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
1774 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
1775 rc_transaction_t *p_transaction=NULL;
1777 if (btif_rc_cb.rc_volume==volume)
1779 status=BT_STATUS_DONE;
1780 BTIF_TRACE_ERROR("%s: volume value already set earlier: 0x%02x",__FUNCTION__, volume);
1784 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG) &&
1785 (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL))
1787 tAVRC_COMMAND avrc_cmd = {0};
1788 BT_HDR *p_msg = NULL;
1790 BTIF_TRACE_DEBUG("%s: Peer supports absolute volume. newVolume=%d", __FUNCTION__, volume);
1791 avrc_cmd.volume.opcode = AVRC_OP_VENDOR;
1792 avrc_cmd.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME;
1793 avrc_cmd.volume.status = AVRC_STS_NO_ERROR;
1794 avrc_cmd.volume.volume = volume;
1796 if (AVRC_BldCommand(&avrc_cmd, &p_msg) == AVRC_STS_NO_ERROR)
1798 bt_status_t tran_status=get_transaction(&p_transaction);
1799 if (BT_STATUS_SUCCESS == tran_status && NULL!=p_transaction)
1801 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
1802 __FUNCTION__,p_transaction->lbl);
1803 BTA_AvMetaCmd(btif_rc_cb.rc_handle,p_transaction->lbl, AVRC_CMD_CTRL, p_msg);
1804 status = BT_STATUS_SUCCESS;
1809 BTIF_TRACE_ERROR("%s: failed to obtain transaction details. status: 0x%02x",
1810 __FUNCTION__, tran_status);
1811 status = BT_STATUS_FAIL;
1816 BTIF_TRACE_ERROR("%s: failed to build absolute volume command. status: 0x%02x",
1817 __FUNCTION__, status);
1818 status = BT_STATUS_FAIL;
1822 status=BT_STATUS_NOT_READY;
1826 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
1827 /***************************************************************************
1829 ** Function register_volumechange
1831 ** Description Register for volume change notification from remote side.
1835 ***************************************************************************/
1837 static void register_volumechange (UINT8 lbl)
1839 tAVRC_COMMAND avrc_cmd = {0};
1840 BT_HDR *p_msg = NULL;
1841 tAVRC_STS BldResp=AVRC_STS_BAD_CMD;
1842 rc_transaction_t *p_transaction=NULL;
1844 BTIF_TRACE_DEBUG("%s called with label:%d",__FUNCTION__,lbl);
1846 avrc_cmd.cmd.opcode=0x00;
1847 avrc_cmd.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
1848 avrc_cmd.reg_notif.event_id = AVRC_EVT_VOLUME_CHANGE;
1849 avrc_cmd.reg_notif.status = AVRC_STS_NO_ERROR;
1850 avrc_cmd.reg_notif.param = 0;
1852 BldResp=AVRC_BldCommand(&avrc_cmd, &p_msg);
1853 if (AVRC_STS_NO_ERROR == BldResp && p_msg) {
1854 p_transaction = get_transaction_by_lbl(lbl);
1855 if (p_transaction != NULL) {
1856 BTA_AvMetaCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
1857 AVRC_CMD_NOTIF, p_msg);
1858 BTIF_TRACE_DEBUG("%s:BTA_AvMetaCmd called", __func__);
1861 BTIF_TRACE_ERROR("%s transaction not obtained with label: %d",
1865 BTIF_TRACE_ERROR("%s failed to build command:%d", __func__, BldResp);
1869 /***************************************************************************
1871 ** Function handle_rc_metamsg_rsp
1873 ** Description Handle RC metamessage response
1877 ***************************************************************************/
1878 static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg)
1880 tAVRC_RESPONSE avrc_response = {0};
1881 UINT8 scratch_buf[512] = {0};
1882 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
1884 if (AVRC_OP_VENDOR==pmeta_msg->p_msg->hdr.opcode &&(AVRC_RSP_CHANGED==pmeta_msg->code
1885 || AVRC_RSP_INTERIM==pmeta_msg->code || AVRC_RSP_ACCEPT==pmeta_msg->code
1886 || AVRC_RSP_REJ==pmeta_msg->code || AVRC_RSP_NOT_IMPL==pmeta_msg->code))
1888 status=AVRC_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, sizeof(scratch_buf));
1889 BTIF_TRACE_DEBUG("%s: code %d,event ID %d,PDU %x,parsing status %d, label:%d",
1890 __FUNCTION__,pmeta_msg->code,avrc_response.reg_notif.event_id,avrc_response.reg_notif.pdu,
1891 status, pmeta_msg->label);
1893 if (status != AVRC_STS_NO_ERROR)
1895 if (AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1896 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1897 && btif_rc_cb.rc_vol_label==pmeta_msg->label)
1899 btif_rc_cb.rc_vol_label=MAX_LABEL;
1900 release_transaction(btif_rc_cb.rc_vol_label);
1902 else if (AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
1904 release_transaction(pmeta_msg->label);
1908 else if (AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1909 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1910 && btif_rc_cb.rc_vol_label!=pmeta_msg->label)
1912 // Just discard the message, if the device sends back with an incorrect label
1913 BTIF_TRACE_DEBUG("%s:Discarding register notfn in rsp.code: %d and label %d",
1914 __FUNCTION__, pmeta_msg->code, pmeta_msg->label);
1920 BTIF_TRACE_DEBUG("%s:Received vendor dependent in adv ctrl rsp. code: %d len: %d. Not processing it.",
1921 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
1925 if (AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1926 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1927 && AVRC_RSP_CHANGED==pmeta_msg->code)
1929 /* re-register for volume change notification */
1930 // Do not re-register for rejected case, as it might get into endless loop
1931 register_volumechange(btif_rc_cb.rc_vol_label);
1933 else if (AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
1935 /* free up the label here */
1936 release_transaction(pmeta_msg->label);
1939 BTIF_TRACE_EVENT("%s: Passing received metamsg response to app. pdu: %s",
1940 __FUNCTION__, dump_rc_pdu(avrc_response.pdu));
1941 btif_rc_upstreams_rsp_evt((uint16_t)avrc_response.rsp.pdu, &avrc_response, pmeta_msg->code,
1946 #if (AVRC_CTLR_INCLUDED == TRUE)
1947 /***************************************************************************
1949 ** Function iterate_supported_event_list_for_interim_rsp
1951 ** Description iterator callback function to match the event and handle
1953 ** Returns true to continue iterating, false to stop
1955 ***************************************************************************/
1956 bool iterate_supported_event_list_for_interim_rsp(void *data, void *cb_data)
1959 btif_rc_supported_event_t *p_event = (btif_rc_supported_event_t *)data;
1961 p_event_id = (UINT8*)cb_data;
1963 if (p_event->event_id == *p_event_id)
1965 p_event->status = eINTERIM;
1971 /***************************************************************************
1973 ** Function iterate_supported_event_list_for_timeout
1975 ** Description Iterator callback function for timeout handling.
1976 ** As part of the failure handling, it releases the
1977 ** transaction label and removes the event from list,
1978 ** this event will not be requested again during
1979 ** the lifetime of the connection.
1980 ** Returns false to stop iterating, true to continue
1982 ***************************************************************************/
1983 bool iterate_supported_event_list_for_timeout(void *data, void *cb_data)
1986 btif_rc_supported_event_t *p_event = (btif_rc_supported_event_t *)data;
1988 label = (*(UINT8*)cb_data) & 0xFF;
1990 if (p_event->label == label)
1992 list_remove(btif_rc_cb.rc_supported_event_list, p_event);
1998 /***************************************************************************
2000 ** Function rc_notification_interim_timout
2002 ** Description Interim response timeout handler.
2003 ** Runs the iterator to check and clear the timed out event.
2004 ** Proceeds to register for the unregistered events.
2007 ***************************************************************************/
2008 static void rc_notification_interim_timout (UINT8 label)
2012 list_foreach(btif_rc_cb.rc_supported_event_list,
2013 iterate_supported_event_list_for_timeout, &label);
2014 /* Timeout happened for interim response for the registered event,
2015 * check if there are any pending for registration
2017 node = list_begin(btif_rc_cb.rc_supported_event_list);
2018 while (node != NULL)
2020 btif_rc_supported_event_t *p_event;
2022 p_event = (btif_rc_supported_event_t *)list_node(node);
2023 if ((p_event != NULL) && (p_event->status == eNOT_REGISTERED))
2025 register_for_event_notification(p_event);
2028 node = list_next (node);
2030 /* Todo. Need to initiate application settings query if this
2031 * is the last event registration.
2035 /***************************************************************************
2037 ** Function btif_rc_status_cmd_timeout_handler
2039 ** Description RC status command timeout handler (Runs in BTIF context).
2042 ***************************************************************************/
2043 static void btif_rc_status_cmd_timeout_handler(UNUSED_ATTR uint16_t event,
2046 btif_rc_timer_context_t *p_context;
2047 tAVRC_RESPONSE avrc_response = {0};
2048 tBTA_AV_META_MSG meta_msg;
2050 p_context = (btif_rc_timer_context_t *)data;
2051 memset(&meta_msg, 0, sizeof(tBTA_AV_META_MSG));
2052 meta_msg.rc_handle = btif_rc_cb.rc_handle;
2054 switch (p_context->rc_status_cmd.pdu_id) {
2055 case AVRC_PDU_REGISTER_NOTIFICATION:
2056 rc_notification_interim_timout(p_context->rc_status_cmd.label);
2059 case AVRC_PDU_GET_CAPABILITIES:
2060 avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
2061 handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
2064 case AVRC_PDU_LIST_PLAYER_APP_ATTR:
2065 avrc_response.list_app_attr.status = BTIF_RC_STS_TIMEOUT;
2066 handle_app_attr_response(&meta_msg, &avrc_response.list_app_attr);
2069 case AVRC_PDU_LIST_PLAYER_APP_VALUES:
2070 avrc_response.list_app_values.status = BTIF_RC_STS_TIMEOUT;
2071 handle_app_val_response(&meta_msg, &avrc_response.list_app_values);
2074 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
2075 avrc_response.get_cur_app_val.status = BTIF_RC_STS_TIMEOUT;
2076 handle_app_cur_val_response(&meta_msg, &avrc_response.get_cur_app_val);
2079 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
2080 avrc_response.get_app_attr_txt.status = BTIF_RC_STS_TIMEOUT;
2081 handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_attr_txt);
2084 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
2085 avrc_response.get_app_val_txt.status = BTIF_RC_STS_TIMEOUT;
2086 handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_val_txt);
2089 case AVRC_PDU_GET_ELEMENT_ATTR:
2090 avrc_response.get_elem_attrs.status = BTIF_RC_STS_TIMEOUT;
2091 handle_get_elem_attr_response(&meta_msg, &avrc_response.get_elem_attrs);
2094 case AVRC_PDU_GET_PLAY_STATUS:
2095 avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
2096 handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
2099 release_transaction(p_context->rc_status_cmd.label);
2102 /***************************************************************************
2104 ** Function btif_rc_status_cmd_timer_timeout
2106 ** Description RC status command timeout callback.
2107 ** This is called from BTU context and switches to BTIF
2108 ** context to handle the timeout events
2111 ***************************************************************************/
2112 static void btif_rc_status_cmd_timer_timeout(void *data)
2114 btif_rc_timer_context_t *p_data = (btif_rc_timer_context_t *)data;
2116 btif_transfer_context(btif_rc_status_cmd_timeout_handler, 0,
2117 (char *)p_data, sizeof(btif_rc_timer_context_t),
2121 /***************************************************************************
2123 ** Function btif_rc_control_cmd_timeout_handler
2125 ** Description RC control command timeout handler (Runs in BTIF context).
2128 ***************************************************************************/
2129 static void btif_rc_control_cmd_timeout_handler(UNUSED_ATTR uint16_t event,
2132 btif_rc_timer_context_t *p_context = (btif_rc_timer_context_t *)data;
2133 tAVRC_RESPONSE avrc_response = {0};
2134 tBTA_AV_META_MSG meta_msg;
2136 memset(&meta_msg, 0, sizeof(tBTA_AV_META_MSG));
2137 meta_msg.rc_handle = btif_rc_cb.rc_handle;
2139 switch (p_context->rc_control_cmd.pdu_id) {
2140 case AVRC_PDU_SET_PLAYER_APP_VALUE:
2141 avrc_response.set_app_val.status = BTIF_RC_STS_TIMEOUT;
2142 handle_set_app_attr_val_response(&meta_msg,
2143 &avrc_response.set_app_val);
2146 release_transaction(p_context->rc_control_cmd.label);
2149 /***************************************************************************
2151 ** Function btif_rc_control_cmd_timer_timeout
2153 ** Description RC control command timeout callback.
2154 ** This is called from BTU context and switches to BTIF
2155 ** context to handle the timeout events
2158 ***************************************************************************/
2159 static void btif_rc_control_cmd_timer_timeout(void *data)
2161 btif_rc_timer_context_t *p_data = (btif_rc_timer_context_t *)data;
2163 btif_transfer_context(btif_rc_control_cmd_timeout_handler, 0,
2164 (char *)p_data, sizeof(btif_rc_timer_context_t),
2168 /***************************************************************************
2170 ** Function btif_rc_play_status_timeout_handler
2172 ** Description RC play status timeout handler (Runs in BTIF context).
2175 ***************************************************************************/
2176 static void btif_rc_play_status_timeout_handler(UNUSED_ATTR uint16_t event,
2177 UNUSED_ATTR char *p_data)
2179 get_play_status_cmd();
2180 rc_start_play_status_timer();
2183 /***************************************************************************
2185 ** Function btif_rc_play_status_timer_timeout
2187 ** Description RC play status timeout callback.
2188 ** This is called from BTU context and switches to BTIF
2189 ** context to handle the timeout events
2192 ***************************************************************************/
2193 static void btif_rc_play_status_timer_timeout(UNUSED_ATTR void *data)
2195 btif_transfer_context(btif_rc_play_status_timeout_handler, 0, 0, 0, NULL);
2198 /***************************************************************************
2200 ** Function rc_start_play_status_timer
2202 ** Description Helper function to start the timer to fetch play status.
2205 ***************************************************************************/
2206 static void rc_start_play_status_timer(void)
2208 /* Start the Play status timer only if it is not started */
2209 if (!alarm_is_scheduled(btif_rc_cb.rc_play_status_timer)) {
2210 if (btif_rc_cb.rc_play_status_timer == NULL) {
2211 btif_rc_cb.rc_play_status_timer =
2212 alarm_new("btif_rc.rc_play_status_timer");
2214 alarm_set_on_queue(btif_rc_cb.rc_play_status_timer,
2215 BTIF_TIMEOUT_RC_INTERIM_RSP_MS,
2216 btif_rc_play_status_timer_timeout, NULL,
2217 btu_general_alarm_queue);
2221 /***************************************************************************
2223 ** Function rc_stop_play_status_timer
2225 ** Description Helper function to stop the play status timer.
2228 ***************************************************************************/
2229 void rc_stop_play_status_timer()
2231 if (btif_rc_cb.rc_play_status_timer != NULL)
2232 alarm_cancel(btif_rc_cb.rc_play_status_timer);
2235 /***************************************************************************
2237 ** Function register_for_event_notification
2239 ** Description Helper function registering notification events
2240 ** sets an interim response timeout to handle if the remote
2241 ** does not respond.
2244 ***************************************************************************/
2245 static void register_for_event_notification(btif_rc_supported_event_t *p_event)
2248 rc_transaction_t *p_transaction;
2250 status = get_transaction(&p_transaction);
2251 if (status == BT_STATUS_SUCCESS)
2253 btif_rc_timer_context_t *p_context = &p_transaction->txn_timer_context;
2255 status = register_notification_cmd (p_transaction->lbl, p_event->event_id, 0);
2256 if (status != BT_STATUS_SUCCESS)
2258 BTIF_TRACE_ERROR("%s Error in Notification registration %d",
2259 __FUNCTION__, status);
2260 release_transaction (p_transaction->lbl);
2263 p_event->label = p_transaction->lbl;
2264 p_event->status = eREGISTERED;
2265 p_context->rc_status_cmd.label = p_transaction->lbl;
2266 p_context->rc_status_cmd.pdu_id = AVRC_PDU_REGISTER_NOTIFICATION;
2268 alarm_free(p_transaction->txn_timer);
2269 p_transaction->txn_timer =
2270 alarm_new("btif_rc.status_command_txn_timer");
2271 alarm_set_on_queue(p_transaction->txn_timer,
2272 BTIF_TIMEOUT_RC_INTERIM_RSP_MS,
2273 btif_rc_status_cmd_timer_timeout, p_context,
2274 btu_general_alarm_queue);
2278 BTIF_TRACE_ERROR("%s Error No more Transaction label %d",
2279 __FUNCTION__, status);
2283 static void start_status_command_timer(UINT8 pdu_id, rc_transaction_t *p_txn)
2285 btif_rc_timer_context_t *p_context = &p_txn->txn_timer_context;
2286 p_context->rc_status_cmd.label = p_txn->lbl;
2287 p_context->rc_status_cmd.pdu_id = pdu_id;
2289 alarm_free(p_txn->txn_timer);
2290 p_txn->txn_timer = alarm_new("btif_rc.status_command_txn_timer");
2291 alarm_set_on_queue(p_txn->txn_timer, BTIF_TIMEOUT_RC_STATUS_CMD_MS,
2292 btif_rc_status_cmd_timer_timeout, p_context,
2293 btu_general_alarm_queue);
2296 static void start_control_command_timer(UINT8 pdu_id, rc_transaction_t *p_txn)
2298 btif_rc_timer_context_t *p_context = &p_txn->txn_timer_context;
2299 p_context->rc_control_cmd.label = p_txn->lbl;
2300 p_context->rc_control_cmd.pdu_id = pdu_id;
2302 alarm_free(p_txn->txn_timer);
2303 p_txn->txn_timer = alarm_new("btif_rc.control_command_txn_timer");
2304 alarm_set_on_queue(p_txn->txn_timer,
2305 BTIF_TIMEOUT_RC_CONTROL_CMD_MS,
2306 btif_rc_control_cmd_timer_timeout, p_context,
2307 btu_general_alarm_queue);
2310 /***************************************************************************
2312 ** Function handle_get_capability_response
2314 ** Description Handles the get_cap_response to populate company id info
2315 ** and query the supported events.
2316 ** Initiates Notification registration for events supported
2319 ***************************************************************************/
2320 static void handle_get_capability_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CAPS_RSP *p_rsp)
2324 /* Todo: Do we need to retry on command timeout */
2325 if (p_rsp->status != AVRC_STS_NO_ERROR)
2327 BTIF_TRACE_ERROR("%s Error capability response 0x%02X",
2328 __FUNCTION__, p_rsp->status);
2332 if (p_rsp->capability_id == AVRC_CAP_EVENTS_SUPPORTED)
2334 btif_rc_supported_event_t *p_event;
2336 /* Todo: Check if list can be active when we hit here */
2337 btif_rc_cb.rc_supported_event_list = list_new(osi_free);
2338 for (xx = 0; xx < p_rsp->count; xx++)
2340 /* Skip registering for Play position change notification */
2341 if ((p_rsp->param.event_id[xx] == AVRC_EVT_PLAY_STATUS_CHANGE)||
2342 (p_rsp->param.event_id[xx] == AVRC_EVT_TRACK_CHANGE)||
2343 (p_rsp->param.event_id[xx] == AVRC_EVT_APP_SETTING_CHANGE))
2345 p_event = (btif_rc_supported_event_t *)osi_malloc(sizeof(btif_rc_supported_event_t));
2346 p_event->event_id = p_rsp->param.event_id[xx];
2347 p_event->status = eNOT_REGISTERED;
2348 list_append(btif_rc_cb.rc_supported_event_list, p_event);
2351 p_event = list_front(btif_rc_cb.rc_supported_event_list);
2352 if (p_event != NULL)
2354 register_for_event_notification(p_event);
2357 else if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID)
2359 getcapabilities_cmd (AVRC_CAP_EVENTS_SUPPORTED);
2360 BTIF_TRACE_EVENT("%s AVRC_CAP_COMPANY_ID: ", __FUNCTION__);
2361 for (xx = 0; xx < p_rsp->count; xx++)
2363 BTIF_TRACE_EVENT("%s : %d", __FUNCTION__, p_rsp->param.company_id[xx]);
2368 bool rc_is_track_id_valid (tAVRC_UID uid)
2370 tAVRC_UID invalid_uid = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
2372 if (memcmp(uid, invalid_uid, sizeof(tAVRC_UID)) == 0)
2382 /***************************************************************************
2384 ** Function handle_notification_response
2386 ** Description Main handler for notification responses to registered events
2387 ** 1. Register for unregistered event(in interim response path)
2388 ** 2. After registering for all supported events, start
2389 ** retrieving application settings and values
2390 ** 3. Reregister for events on getting changed response
2391 ** 4. Run play status timer for getting position when the
2392 ** status changes to playing
2393 ** 5. Get the Media details when the track change happens
2394 ** or track change interim response is received with
2396 ** 6. HAL callback for play status change and application
2400 ***************************************************************************/
2401 static void handle_notification_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_REG_NOTIF_RSP *p_rsp)
2403 bt_bdaddr_t rc_addr;
2404 UINT32 attr_list[] = {
2405 AVRC_MEDIA_ATTR_ID_TITLE,
2406 AVRC_MEDIA_ATTR_ID_ARTIST,
2407 AVRC_MEDIA_ATTR_ID_ALBUM,
2408 AVRC_MEDIA_ATTR_ID_TRACK_NUM,
2409 AVRC_MEDIA_ATTR_ID_NUM_TRACKS,
2410 AVRC_MEDIA_ATTR_ID_GENRE,
2411 AVRC_MEDIA_ATTR_ID_PLAYING_TIME
2415 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2417 if (pmeta_msg->code == AVRC_RSP_INTERIM)
2419 btif_rc_supported_event_t *p_event;
2422 BTIF_TRACE_DEBUG("%s Interim response : 0x%2X ", __FUNCTION__, p_rsp->event_id);
2423 switch (p_rsp->event_id)
2425 case AVRC_EVT_PLAY_STATUS_CHANGE:
2426 /* Start timer to get play status periodically
2427 * if the play state is playing.
2429 if (p_rsp->param.play_status == AVRC_PLAYSTATE_PLAYING)
2431 rc_start_play_status_timer();
2433 HAL_CBACK(bt_rc_ctrl_callbacks, play_status_changed_cb,
2434 &rc_addr, p_rsp->param.play_status);
2437 case AVRC_EVT_TRACK_CHANGE:
2438 if (rc_is_track_id_valid (p_rsp->param.track) != true)
2444 UINT8 *p_data = p_rsp->param.track;
2445 /* Update the UID for current track
2446 * Attributes will be fetched after the AVRCP procedure
2448 BE_STREAM_TO_UINT64(btif_rc_cb.rc_playing_uid, p_data);
2452 case AVRC_EVT_APP_SETTING_CHANGE:
2455 case AVRC_EVT_NOW_PLAYING_CHANGE:
2458 case AVRC_EVT_AVAL_PLAYERS_CHANGE:
2461 case AVRC_EVT_ADDR_PLAYER_CHANGE:
2464 case AVRC_EVT_UIDS_CHANGE:
2467 case AVRC_EVT_TRACK_REACHED_END:
2468 case AVRC_EVT_TRACK_REACHED_START:
2469 case AVRC_EVT_PLAY_POS_CHANGED:
2470 case AVRC_EVT_BATTERY_STATUS_CHANGE:
2471 case AVRC_EVT_SYSTEM_STATUS_CHANGE:
2473 BTIF_TRACE_ERROR("%s Unhandled interim response 0x%2X", __FUNCTION__,
2477 list_foreach(btif_rc_cb.rc_supported_event_list,
2478 iterate_supported_event_list_for_interim_rsp,
2481 node = list_begin(btif_rc_cb.rc_supported_event_list);
2482 while (node != NULL)
2484 p_event = (btif_rc_supported_event_t *)list_node(node);
2485 if ((p_event != NULL) && (p_event->status == eNOT_REGISTERED))
2487 register_for_event_notification(p_event);
2490 node = list_next (node);
2493 /* Registered for all events, we can request application settings */
2494 if ((p_event == NULL) && (btif_rc_cb.rc_app_settings.query_started == false))
2496 /* we need to do this only if remote TG supports
2497 * player application settings
2499 btif_rc_cb.rc_app_settings.query_started = TRUE;
2500 if (btif_rc_cb.rc_features & BTA_AV_FEAT_APP_SETTING)
2502 list_player_app_setting_attrib_cmd();
2506 BTIF_TRACE_DEBUG("%s App setting not supported, complete procedure", __FUNCTION__);
2507 rc_ctrl_procedure_complete();
2511 else if (pmeta_msg->code == AVRC_RSP_CHANGED)
2513 btif_rc_supported_event_t *p_event;
2516 BTIF_TRACE_DEBUG("%s Notification completed : 0x%2X ", __FUNCTION__,
2519 node = list_begin(btif_rc_cb.rc_supported_event_list);
2520 while (node != NULL)
2522 p_event = (btif_rc_supported_event_t *)list_node(node);
2523 if ((p_event != NULL) && (p_event->event_id == p_rsp->event_id))
2525 p_event->status = eNOT_REGISTERED;
2526 register_for_event_notification(p_event);
2529 node = list_next (node);
2532 switch (p_rsp->event_id)
2534 case AVRC_EVT_PLAY_STATUS_CHANGE:
2535 /* Start timer to get play status periodically
2536 * if the play state is playing.
2538 if (p_rsp->param.play_status == AVRC_PLAYSTATE_PLAYING)
2540 rc_start_play_status_timer();
2544 rc_stop_play_status_timer();
2546 HAL_CBACK(bt_rc_ctrl_callbacks, play_status_changed_cb,
2547 &rc_addr, p_rsp->param.play_status);
2550 case AVRC_EVT_TRACK_CHANGE:
2551 if (rc_is_track_id_valid (p_rsp->param.track) != true)
2555 get_element_attribute_cmd (AVRC_MAX_NUM_MEDIA_ATTR_ID, attr_list);
2558 case AVRC_EVT_APP_SETTING_CHANGE:
2560 btrc_player_settings_t app_settings;
2563 app_settings.num_attr = p_rsp->param.player_setting.num_attr;
2564 for (xx = 0; xx < app_settings.num_attr; xx++)
2566 app_settings.attr_ids[xx] = p_rsp->param.player_setting.attr_id[xx];
2567 app_settings.attr_values[xx] = p_rsp->param.player_setting.attr_value[xx];
2569 HAL_CBACK(bt_rc_ctrl_callbacks, playerapplicationsetting_changed_cb,
2570 &rc_addr, &app_settings);
2574 case AVRC_EVT_NOW_PLAYING_CHANGE:
2577 case AVRC_EVT_AVAL_PLAYERS_CHANGE:
2580 case AVRC_EVT_ADDR_PLAYER_CHANGE:
2583 case AVRC_EVT_UIDS_CHANGE:
2586 case AVRC_EVT_TRACK_REACHED_END:
2587 case AVRC_EVT_TRACK_REACHED_START:
2588 case AVRC_EVT_PLAY_POS_CHANGED:
2589 case AVRC_EVT_BATTERY_STATUS_CHANGE:
2590 case AVRC_EVT_SYSTEM_STATUS_CHANGE:
2592 BTIF_TRACE_ERROR("%s Unhandled completion response 0x%2X",
2593 __FUNCTION__, p_rsp->event_id);
2599 /***************************************************************************
2601 ** Function handle_app_attr_response
2603 ** Description handles the the application attributes response and
2604 ** initiates procedure to fetch the attribute values
2607 ***************************************************************************/
2608 static void handle_app_attr_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_ATTR_RSP *p_rsp)
2612 if (p_rsp->status != AVRC_STS_NO_ERROR)
2614 BTIF_TRACE_ERROR("%s Error getting Player application settings: 0x%2X",
2615 __FUNCTION__, p_rsp->status);
2616 rc_ctrl_procedure_complete();
2620 for (xx = 0; xx < p_rsp->num_attr; xx++)
2624 if (p_rsp->attrs[xx] > AVRC_PLAYER_SETTING_LOW_MENU_EXT)
2626 st_index = btif_rc_cb.rc_app_settings.num_ext_attrs;
2627 btif_rc_cb.rc_app_settings.ext_attrs[st_index].attr_id = p_rsp->attrs[xx];
2628 btif_rc_cb.rc_app_settings.num_ext_attrs++;
2632 st_index = btif_rc_cb.rc_app_settings.num_attrs;
2633 btif_rc_cb.rc_app_settings.attrs[st_index].attr_id = p_rsp->attrs[xx];
2634 btif_rc_cb.rc_app_settings.num_attrs++;
2637 btif_rc_cb.rc_app_settings.attr_index = 0;
2638 btif_rc_cb.rc_app_settings.ext_attr_index = 0;
2639 btif_rc_cb.rc_app_settings.ext_val_index = 0;
2640 if (p_rsp->num_attr)
2642 list_player_app_setting_value_cmd (btif_rc_cb.rc_app_settings.attrs[0].attr_id);
2646 BTIF_TRACE_ERROR("%s No Player application settings found",
2651 /***************************************************************************
2653 ** Function handle_app_val_response
2655 ** Description handles the the attributes value response and if extended
2656 ** menu is available, it initiates query for the attribute
2657 ** text. If not, it initiates procedure to get the current
2658 ** attribute values and calls the HAL callback for provding
2659 ** application settings information.
2662 ***************************************************************************/
2663 static void handle_app_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_VALUES_RSP *p_rsp)
2665 UINT8 xx, attr_index;
2666 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2667 btif_rc_player_app_settings_t *p_app_settings;
2668 bt_bdaddr_t rc_addr;
2670 /* Todo: Do we need to retry on command timeout */
2671 if (p_rsp->status != AVRC_STS_NO_ERROR)
2673 BTIF_TRACE_ERROR("%s Error fetching attribute values 0x%02X",
2674 __FUNCTION__, p_rsp->status);
2678 p_app_settings = &btif_rc_cb.rc_app_settings;
2679 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2681 if (p_app_settings->attr_index < p_app_settings->num_attrs)
2683 attr_index = p_app_settings->attr_index;
2684 p_app_settings->attrs[attr_index].num_val = p_rsp->num_val;
2685 for (xx = 0; xx < p_rsp->num_val; xx++)
2687 p_app_settings->attrs[attr_index].attr_val[xx] = p_rsp->vals[xx];
2690 p_app_settings->attr_index++;
2691 if (attr_index < p_app_settings->num_attrs)
2693 list_player_app_setting_value_cmd (p_app_settings->attrs[p_app_settings->attr_index].attr_id);
2695 else if (p_app_settings->ext_attr_index < p_app_settings->num_ext_attrs)
2698 p_app_settings->ext_attr_index = 0;
2699 list_player_app_setting_value_cmd (p_app_settings->ext_attrs[attr_index].attr_id);
2703 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2705 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2707 get_player_app_setting_cmd (p_app_settings->num_attrs, attrs);
2708 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2709 p_app_settings->num_attrs, p_app_settings->attrs, 0, NULL);
2712 else if (p_app_settings->ext_attr_index < p_app_settings->num_ext_attrs)
2714 attr_index = p_app_settings->ext_attr_index;
2715 p_app_settings->ext_attrs[attr_index].num_val = p_rsp->num_val;
2716 for (xx = 0; xx < p_rsp->num_val; xx++)
2718 p_app_settings->ext_attrs[attr_index].ext_attr_val[xx].val = p_rsp->vals[xx];
2721 p_app_settings->ext_attr_index++;
2722 if (attr_index < p_app_settings->num_ext_attrs)
2724 list_player_app_setting_value_cmd (p_app_settings->ext_attrs[p_app_settings->ext_attr_index].attr_id);
2728 UINT8 attr[AVRC_MAX_APP_ATTR_SIZE];
2731 for (xx = 0; xx < p_app_settings->num_ext_attrs; xx++)
2733 attr[xx] = p_app_settings->ext_attrs[xx].attr_id;
2735 get_player_app_setting_attr_text_cmd(attr, xx);
2740 /***************************************************************************
2742 ** Function handle_app_cur_val_response
2744 ** Description handles the the get attributes value response.
2748 ***************************************************************************/
2749 static void handle_app_cur_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp)
2751 btrc_player_settings_t app_settings;
2752 bt_bdaddr_t rc_addr;
2755 /* Todo: Do we need to retry on command timeout */
2756 if (p_rsp->status != AVRC_STS_NO_ERROR)
2758 BTIF_TRACE_ERROR("%s Error fetching current settings: 0x%02X",
2759 __FUNCTION__, p_rsp->status);
2763 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2765 app_settings.num_attr = p_rsp->num_val;
2766 for (xx = 0; xx < app_settings.num_attr; xx++)
2768 app_settings.attr_ids[xx] = p_rsp->p_vals[xx].attr_id;
2769 app_settings.attr_values[xx] = p_rsp->p_vals[xx].attr_val;
2771 HAL_CBACK(bt_rc_ctrl_callbacks, playerapplicationsetting_changed_cb,
2772 &rc_addr, &app_settings);
2773 /* Application settings are fetched only once for initial values
2774 * initiate anything that follows after RC procedure.
2775 * Defer it if browsing is supported till players query
2777 rc_ctrl_procedure_complete ();
2778 osi_free_and_reset((void **)&p_rsp->p_vals);
2781 /***************************************************************************
2783 ** Function handle_app_attr_txt_response
2785 ** Description handles the the get attributes text response, if fails
2786 ** calls HAL callback with just normal settings and initiates
2787 ** query for current settings else initiates query for value text
2790 ***************************************************************************/
2791 static void handle_app_attr_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp)
2794 UINT8 vals[AVRC_MAX_APP_ATTR_SIZE];
2795 btif_rc_player_app_settings_t *p_app_settings;
2796 bt_bdaddr_t rc_addr;
2798 p_app_settings = &btif_rc_cb.rc_app_settings;
2799 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2801 /* Todo: Do we need to retry on command timeout */
2802 if (p_rsp->status != AVRC_STS_NO_ERROR)
2804 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2806 BTIF_TRACE_ERROR("%s Error fetching attribute text: 0x%02X",
2807 __FUNCTION__, p_rsp->status);
2808 /* Not able to fetch Text for extended Menu, skip the process
2809 * and cleanup used memory. Proceed to get the current settings
2810 * for standard attributes.
2812 p_app_settings->num_ext_attrs = 0;
2813 for (xx = 0; xx < p_app_settings->ext_attr_index; xx++)
2814 osi_free_and_reset((void **)&p_app_settings->ext_attrs[xx].p_str);
2815 p_app_settings->ext_attr_index = 0;
2817 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2819 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2821 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2822 p_app_settings->num_attrs, p_app_settings->attrs, 0, NULL);
2824 get_player_app_setting_cmd (xx, attrs);
2828 for (xx = 0; xx < p_rsp->num_attr; xx++)
2831 for (x = 0; x < p_app_settings->num_ext_attrs; x++)
2833 if (p_app_settings->ext_attrs[x].attr_id == p_rsp->p_attrs[xx].attr_id)
2835 p_app_settings->ext_attrs[x].charset_id = p_rsp->p_attrs[xx].charset_id;
2836 p_app_settings->ext_attrs[x].str_len = p_rsp->p_attrs[xx].str_len;
2837 p_app_settings->ext_attrs[x].p_str = p_rsp->p_attrs[xx].p_str;
2843 for (xx = 0; xx < p_app_settings->ext_attrs[0].num_val; xx++)
2845 vals[xx] = p_app_settings->ext_attrs[0].ext_attr_val[xx].val;
2847 get_player_app_setting_value_text_cmd(vals, xx);
2851 /***************************************************************************
2853 ** Function handle_app_attr_val_txt_response
2855 ** Description handles the the get attributes value text response, if fails
2856 ** calls HAL callback with just normal settings and initiates
2857 ** query for current settings
2860 ***************************************************************************/
2861 static void handle_app_attr_val_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp)
2863 UINT8 xx, attr_index;
2864 UINT8 vals[AVRC_MAX_APP_ATTR_SIZE];
2865 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2866 btif_rc_player_app_settings_t *p_app_settings;
2867 bt_bdaddr_t rc_addr;
2869 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2870 p_app_settings = &btif_rc_cb.rc_app_settings;
2872 /* Todo: Do we need to retry on command timeout */
2873 if (p_rsp->status != AVRC_STS_NO_ERROR)
2875 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2877 BTIF_TRACE_ERROR("%s Error fetching attribute value text: 0x%02X",
2878 __FUNCTION__, p_rsp->status);
2880 /* Not able to fetch Text for extended Menu, skip the process
2881 * and cleanup used memory. Proceed to get the current settings
2882 * for standard attributes.
2884 p_app_settings->num_ext_attrs = 0;
2885 for (xx = 0; xx < p_app_settings->ext_attr_index; xx++)
2888 btrc_player_app_ext_attr_t *p_ext_attr = &p_app_settings->ext_attrs[xx];
2890 for (x = 0; x < p_ext_attr->num_val; x++)
2891 osi_free_and_reset((void **)&p_ext_attr->ext_attr_val[x].p_str);
2892 p_ext_attr->num_val = 0;
2893 osi_free_and_reset((void **)&p_app_settings->ext_attrs[xx].p_str);
2895 p_app_settings->ext_attr_index = 0;
2897 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2899 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2901 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2902 p_app_settings->num_attrs, p_app_settings->attrs, 0, NULL);
2904 get_player_app_setting_cmd (xx, attrs);
2908 for (xx = 0; xx < p_rsp->num_attr; xx++)
2911 btrc_player_app_ext_attr_t *p_ext_attr;
2912 p_ext_attr = &p_app_settings->ext_attrs[p_app_settings->ext_val_index];
2913 for (x = 0; x < p_rsp->num_attr; x++)
2915 if (p_ext_attr->ext_attr_val[x].val == p_rsp->p_attrs[xx].attr_id)
2917 p_ext_attr->ext_attr_val[x].charset_id = p_rsp->p_attrs[xx].charset_id;
2918 p_ext_attr->ext_attr_val[x].str_len = p_rsp->p_attrs[xx].str_len;
2919 p_ext_attr->ext_attr_val[x].p_str = p_rsp->p_attrs[xx].p_str;
2924 p_app_settings->ext_val_index++;
2926 if (p_app_settings->ext_val_index < p_app_settings->num_ext_attrs)
2928 attr_index = p_app_settings->ext_val_index;
2929 for (xx = 0; xx < p_app_settings->ext_attrs[attr_index].num_val; xx++)
2931 vals[xx] = p_app_settings->ext_attrs[attr_index].ext_attr_val[xx].val;
2933 get_player_app_setting_value_text_cmd(vals, xx);
2939 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2941 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2943 for (x = 0; x < p_app_settings->num_ext_attrs; x++)
2945 attrs[xx+x] = p_app_settings->ext_attrs[x].attr_id;
2947 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2948 p_app_settings->num_attrs, p_app_settings->attrs,
2949 p_app_settings->num_ext_attrs, p_app_settings->ext_attrs);
2950 get_player_app_setting_cmd (xx + x, attrs);
2952 /* Free the application settings information after sending to
2955 for (xx = 0; xx < p_app_settings->ext_attr_index; xx++)
2958 btrc_player_app_ext_attr_t *p_ext_attr = &p_app_settings->ext_attrs[xx];
2960 for (x = 0; x < p_ext_attr->num_val; x++)
2961 osi_free_and_reset((void **)&p_ext_attr->ext_attr_val[x].p_str);
2962 p_ext_attr->num_val = 0;
2963 osi_free_and_reset((void **)&p_app_settings->ext_attrs[xx].p_str);
2965 p_app_settings->num_attrs = 0;
2969 /***************************************************************************
2971 ** Function handle_set_app_attr_val_response
2973 ** Description handles the the set attributes value response, if fails
2974 ** calls HAL callback to indicate the failure
2977 ***************************************************************************/
2978 static void handle_set_app_attr_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_RSP *p_rsp)
2980 uint8_t accepted = 0;
2981 bt_bdaddr_t rc_addr;
2983 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2985 /* For timeout pmeta_msg will be NULL, else we need to
2986 * check if this is accepted by TG
2988 if (pmeta_msg && (pmeta_msg->code == AVRC_RSP_ACCEPT))
2992 HAL_CBACK(bt_rc_ctrl_callbacks, setplayerappsetting_rsp_cb, &rc_addr, accepted);
2995 /***************************************************************************
2997 ** Function handle_get_elem_attr_response
2999 ** Description handles the the element attributes response, calls
3000 ** HAL callback to update track change information.
3003 ***************************************************************************/
3004 static void handle_get_elem_attr_response (tBTA_AV_META_MSG *pmeta_msg,
3005 tAVRC_GET_ELEM_ATTRS_RSP *p_rsp)
3007 if (p_rsp->status == AVRC_STS_NO_ERROR) {
3008 bt_bdaddr_t rc_addr;
3009 size_t buf_size = p_rsp->num_attr * sizeof(btrc_element_attr_val_t);
3010 btrc_element_attr_val_t *p_attr =
3011 (btrc_element_attr_val_t *)osi_calloc(buf_size);
3013 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
3015 for (int i = 0; i < p_rsp->num_attr; i++) {
3016 p_attr[i].attr_id = p_rsp->p_attrs[i].attr_id;
3017 /* Todo. Legth limit check to include null */
3018 if (p_rsp->p_attrs[i].name.str_len &&
3019 p_rsp->p_attrs[i].name.p_str) {
3020 memcpy(p_attr[i].text, p_rsp->p_attrs[i].name.p_str,
3021 p_rsp->p_attrs[i].name.str_len);
3022 osi_free_and_reset((void **)&p_rsp->p_attrs[i].name.p_str);
3025 HAL_CBACK(bt_rc_ctrl_callbacks, track_changed_cb,
3026 &rc_addr, p_rsp->num_attr, p_attr);
3028 } else if (p_rsp->status == BTIF_RC_STS_TIMEOUT) {
3029 /* Retry for timeout case, this covers error handling
3030 * for continuation failure also.
3032 UINT32 attr_list[] = {
3033 AVRC_MEDIA_ATTR_ID_TITLE,
3034 AVRC_MEDIA_ATTR_ID_ARTIST,
3035 AVRC_MEDIA_ATTR_ID_ALBUM,
3036 AVRC_MEDIA_ATTR_ID_TRACK_NUM,
3037 AVRC_MEDIA_ATTR_ID_NUM_TRACKS,
3038 AVRC_MEDIA_ATTR_ID_GENRE,
3039 AVRC_MEDIA_ATTR_ID_PLAYING_TIME
3041 get_element_attribute_cmd (AVRC_MAX_NUM_MEDIA_ATTR_ID, attr_list);
3043 BTIF_TRACE_ERROR("%s: Error in get element attr procedure %d",
3044 __func__, p_rsp->status);
3048 /***************************************************************************
3050 ** Function handle_get_playstatus_response
3052 ** Description handles the the play status response, calls
3053 ** HAL callback to update play position.
3056 ***************************************************************************/
3057 static void handle_get_playstatus_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_PLAY_STATUS_RSP *p_rsp)
3059 bt_bdaddr_t rc_addr;
3061 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
3063 if (p_rsp->status == AVRC_STS_NO_ERROR)
3065 HAL_CBACK(bt_rc_ctrl_callbacks, play_position_changed_cb,
3066 &rc_addr, p_rsp->song_len, p_rsp->song_pos);
3070 BTIF_TRACE_ERROR("%s: Error in get play status procedure %d",
3071 __FUNCTION__, p_rsp->status);
3075 /***************************************************************************
3077 ** Function clear_cmd_timeout
3079 ** Description helper function to stop the command timeout timer
3082 ***************************************************************************/
3083 static void clear_cmd_timeout (UINT8 label)
3085 rc_transaction_t *p_txn;
3087 p_txn = get_transaction_by_lbl (label);
3090 BTIF_TRACE_ERROR("%s: Error in transaction label lookup", __FUNCTION__);
3094 if (p_txn->txn_timer != NULL)
3095 alarm_cancel(p_txn->txn_timer);
3098 /***************************************************************************
3100 ** Function handle_avk_rc_metamsg_rsp
3102 ** Description Handle RC metamessage response
3106 ***************************************************************************/
3107 static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg)
3109 tAVRC_RESPONSE avrc_response = {0};
3110 UINT8 scratch_buf[512] = {0};// this variable is unused
3114 BTIF_TRACE_DEBUG("%s opcode = %d rsp_code = %d ", __FUNCTION__,
3115 pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code);
3117 if ((AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode)&&
3118 (pmeta_msg->code >= AVRC_RSP_NOT_IMPL)&&
3119 (pmeta_msg->code <= AVRC_RSP_INTERIM))
3121 status = AVRC_Ctrl_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, &buf_len);
3122 BTIF_TRACE_DEBUG("%s parse status %d pdu = %d rsp_status = %d",
3123 __FUNCTION__, status, avrc_response.pdu,
3124 pmeta_msg->p_msg->vendor.hdr.ctype);
3126 switch (avrc_response.pdu)
3128 case AVRC_PDU_REGISTER_NOTIFICATION:
3129 handle_notification_response(pmeta_msg, &avrc_response.reg_notif);
3130 if (pmeta_msg->code == AVRC_RSP_INTERIM)
3132 /* Don't free the transaction Id */
3133 clear_cmd_timeout (pmeta_msg->label);
3138 case AVRC_PDU_GET_CAPABILITIES:
3139 handle_get_capability_response(pmeta_msg, &avrc_response.get_caps);
3142 case AVRC_PDU_LIST_PLAYER_APP_ATTR:
3143 handle_app_attr_response(pmeta_msg, &avrc_response.list_app_attr);
3146 case AVRC_PDU_LIST_PLAYER_APP_VALUES:
3147 handle_app_val_response(pmeta_msg, &avrc_response.list_app_values);
3150 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
3151 handle_app_cur_val_response(pmeta_msg, &avrc_response.get_cur_app_val);
3154 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
3155 handle_app_attr_txt_response(pmeta_msg, &avrc_response.get_app_attr_txt);
3158 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
3159 handle_app_attr_val_txt_response(pmeta_msg, &avrc_response.get_app_val_txt);
3162 case AVRC_PDU_SET_PLAYER_APP_VALUE:
3163 handle_set_app_attr_val_response(pmeta_msg, &avrc_response.set_app_val);
3166 case AVRC_PDU_GET_ELEMENT_ATTR:
3167 handle_get_elem_attr_response(pmeta_msg, &avrc_response.get_elem_attrs);
3170 case AVRC_PDU_GET_PLAY_STATUS:
3171 handle_get_playstatus_response(pmeta_msg, &avrc_response.get_play_status);
3174 release_transaction(pmeta_msg->label);
3178 BTIF_TRACE_DEBUG("%s:Invalid Vendor Command code: %d len: %d. Not processing it.",
3179 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
3184 /***************************************************************************
3186 ** Function handle_avk_rc_metamsg_cmd
3188 ** Description Handle RC metamessage response
3192 ***************************************************************************/
3193 static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG *pmeta_msg)
3195 tAVRC_COMMAND avrc_cmd = {0};
3196 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3197 BTIF_TRACE_DEBUG("%s opcode = %d rsp_code = %d ",__FUNCTION__,
3198 pmeta_msg->p_msg->hdr.opcode,pmeta_msg->code);
3199 if ((AVRC_OP_VENDOR==pmeta_msg->p_msg->hdr.opcode)&&
3200 (pmeta_msg->code <= AVRC_CMD_GEN_INQ))
3202 status = AVRC_Ctrl_ParsCommand(pmeta_msg->p_msg, &avrc_cmd);
3203 BTIF_TRACE_DEBUG("%s Received vendor command.code %d, PDU %d label %d",
3204 __FUNCTION__, pmeta_msg->code, avrc_cmd.pdu, pmeta_msg->label);
3206 if (status != AVRC_STS_NO_ERROR)
3209 BTIF_TRACE_WARNING("%s: Error in parsing received metamsg command. status: 0x%02x",
3210 __FUNCTION__, status);
3211 send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_cmd.pdu, status);
3215 if (avrc_cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION)
3217 UINT8 event_id = avrc_cmd.reg_notif.event_id;
3218 BTIF_TRACE_EVENT("%s:Register notification event_id: %s",
3219 __FUNCTION__, dump_rc_notification_event_id(event_id));
3221 else if (avrc_cmd.pdu == AVRC_PDU_SET_ABSOLUTE_VOLUME)
3223 BTIF_TRACE_EVENT("%s: Abs Volume Cmd Recvd", __FUNCTION__);
3225 btif_rc_ctrl_upstreams_rsp_cmd(avrc_cmd.pdu, &avrc_cmd, pmeta_msg->label);
3230 BTIF_TRACE_DEBUG("%s:Invalid Vendor Command code: %d len: %d. Not processing it.",
3231 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
3237 /***************************************************************************
3241 ** Description Closes the AVRC interface
3245 ***************************************************************************/
3246 static void cleanup()
3248 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
3250 if (bt_rc_callbacks)
3252 bt_rc_callbacks = NULL;
3254 alarm_free(btif_rc_cb.rc_play_status_timer);
3255 memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
3257 BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
3260 /***************************************************************************
3262 ** Function cleanup_ctrl
3264 ** Description Closes the AVRC Controller interface
3268 ***************************************************************************/
3269 static void cleanup_ctrl()
3271 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
3273 if (bt_rc_ctrl_callbacks)
3275 bt_rc_ctrl_callbacks = NULL;
3277 alarm_free(btif_rc_cb.rc_play_status_timer);
3278 memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
3280 BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
3283 /***************************************************************************
3285 ** Function getcapabilities_cmd
3287 ** Description GetCapabilties from Remote(Company_ID, Events_Supported)
3291 ***************************************************************************/
3292 static bt_status_t getcapabilities_cmd (uint8_t cap_id)
3294 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3295 rc_transaction_t *p_transaction = NULL;
3296 #if (AVRC_CTLR_INCLUDED == TRUE)
3297 BTIF_TRACE_DEBUG("%s: cap_id %d", __FUNCTION__, cap_id);
3299 bt_status_t tran_status=get_transaction(&p_transaction);
3300 if (BT_STATUS_SUCCESS != tran_status)
3301 return BT_STATUS_FAIL;
3303 tAVRC_COMMAND avrc_cmd = {0};
3304 BT_HDR *p_msg = NULL;
3305 avrc_cmd.get_caps.opcode = AVRC_OP_VENDOR;
3306 avrc_cmd.get_caps.capability_id = cap_id;
3307 avrc_cmd.get_caps.pdu = AVRC_PDU_GET_CAPABILITIES;
3308 avrc_cmd.get_caps.status = AVRC_STS_NO_ERROR;
3309 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3310 if ((status == AVRC_STS_NO_ERROR)&&(p_msg != NULL))
3312 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3313 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3314 __FUNCTION__,p_transaction->lbl);
3315 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3316 data_start, p_msg->len);
3317 status = BT_STATUS_SUCCESS;
3318 start_status_command_timer (AVRC_PDU_GET_CAPABILITIES, p_transaction);
3322 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3323 __FUNCTION__, status);
3327 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3332 /***************************************************************************
3334 ** Function list_player_app_setting_attrib_cmd
3336 ** Description Get supported List Player Attributes
3340 ***************************************************************************/
3341 static bt_status_t list_player_app_setting_attrib_cmd(void)
3343 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3344 rc_transaction_t *p_transaction = NULL;
3345 #if (AVRC_CTLR_INCLUDED == TRUE)
3346 BTIF_TRACE_DEBUG("%s: ", __FUNCTION__);
3348 bt_status_t tran_status=get_transaction(&p_transaction);
3349 if (BT_STATUS_SUCCESS != tran_status)
3350 return BT_STATUS_FAIL;
3352 tAVRC_COMMAND avrc_cmd = {0};
3353 BT_HDR *p_msg = NULL;
3354 avrc_cmd.list_app_attr.opcode = AVRC_OP_VENDOR;
3355 avrc_cmd.list_app_attr.pdu = AVRC_PDU_LIST_PLAYER_APP_ATTR;
3356 avrc_cmd.list_app_attr.status = AVRC_STS_NO_ERROR;
3357 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3358 if ((status == AVRC_STS_NO_ERROR)&&(p_msg != NULL))
3360 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3361 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3362 __FUNCTION__,p_transaction->lbl);
3363 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3364 data_start, p_msg->len);
3365 status = BT_STATUS_SUCCESS;
3366 start_status_command_timer (AVRC_PDU_LIST_PLAYER_APP_ATTR, p_transaction);
3371 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3372 __FUNCTION__, status);
3376 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3381 /***************************************************************************
3383 ** Function list_player_app_setting_value_cmd
3385 ** Description Get values of supported Player Attributes
3389 ***************************************************************************/
3390 static bt_status_t list_player_app_setting_value_cmd(uint8_t attrib_id)
3392 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3393 rc_transaction_t *p_transaction=NULL;
3394 #if (AVRC_CTLR_INCLUDED == TRUE)
3395 BTIF_TRACE_DEBUG("%s: attrib_id %d", __FUNCTION__, attrib_id);
3397 bt_status_t tran_status=get_transaction(&p_transaction);
3398 if (BT_STATUS_SUCCESS != tran_status)
3399 return BT_STATUS_FAIL;
3401 tAVRC_COMMAND avrc_cmd = {0};
3402 BT_HDR *p_msg = NULL;
3403 avrc_cmd.list_app_values.attr_id = attrib_id;
3404 avrc_cmd.list_app_values.opcode = AVRC_OP_VENDOR;
3405 avrc_cmd.list_app_values.pdu = AVRC_PDU_LIST_PLAYER_APP_VALUES;
3406 avrc_cmd.list_app_values.status = AVRC_STS_NO_ERROR;
3407 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3408 if ((status == AVRC_STS_NO_ERROR) && (p_msg != NULL))
3410 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3411 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3412 __FUNCTION__,p_transaction->lbl);
3413 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3414 data_start, p_msg->len);
3415 status = BT_STATUS_SUCCESS;
3416 start_status_command_timer (AVRC_PDU_LIST_PLAYER_APP_VALUES, p_transaction);
3420 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x", __FUNCTION__, status);
3424 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3429 /***************************************************************************
3431 ** Function get_player_app_setting_cmd
3433 ** Description Get current values of Player Attributes
3437 ***************************************************************************/
3438 static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib, uint8_t* attrib_ids)
3440 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3441 rc_transaction_t *p_transaction = NULL;
3443 #if (AVRC_CTLR_INCLUDED == TRUE)
3444 BTIF_TRACE_DEBUG("%s: num attrib_id %d", __FUNCTION__, num_attrib);
3446 bt_status_t tran_status=get_transaction(&p_transaction);
3447 if (BT_STATUS_SUCCESS != tran_status)
3448 return BT_STATUS_FAIL;
3450 tAVRC_COMMAND avrc_cmd = {0};
3451 BT_HDR *p_msg = NULL;
3452 avrc_cmd.get_cur_app_val.opcode = AVRC_OP_VENDOR;
3453 avrc_cmd.get_cur_app_val.status = AVRC_STS_NO_ERROR;
3454 avrc_cmd.get_cur_app_val.num_attr = num_attrib;
3455 avrc_cmd.get_cur_app_val.pdu = AVRC_PDU_GET_CUR_PLAYER_APP_VALUE;
3457 for (count = 0; count < num_attrib; count++)
3459 avrc_cmd.get_cur_app_val.attrs[count] = attrib_ids[count];
3461 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3462 if ((status == AVRC_STS_NO_ERROR) && (p_msg != NULL))
3464 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3465 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3466 __FUNCTION__,p_transaction->lbl);
3467 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3468 data_start, p_msg->len);
3469 status = BT_STATUS_SUCCESS;
3470 start_status_command_timer (AVRC_PDU_GET_CUR_PLAYER_APP_VALUE, p_transaction);
3474 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3475 __FUNCTION__, status);
3479 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3484 /***************************************************************************
3486 ** Function change_player_app_setting
3488 ** Description Set current values of Player Attributes
3492 ***************************************************************************/
3493 static bt_status_t change_player_app_setting(bt_bdaddr_t *bd_addr, uint8_t num_attrib, uint8_t* attrib_ids, uint8_t* attrib_vals)
3495 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3496 rc_transaction_t *p_transaction = NULL;
3498 #if (AVRC_CTLR_INCLUDED == TRUE)
3499 BTIF_TRACE_DEBUG("%s: num attrib_id %d", __FUNCTION__, num_attrib);
3501 bt_status_t tran_status=get_transaction(&p_transaction);
3502 if (BT_STATUS_SUCCESS != tran_status)
3503 return BT_STATUS_FAIL;
3505 tAVRC_COMMAND avrc_cmd = {0};
3506 BT_HDR *p_msg = NULL;
3507 avrc_cmd.set_app_val.opcode = AVRC_OP_VENDOR;
3508 avrc_cmd.set_app_val.status = AVRC_STS_NO_ERROR;
3509 avrc_cmd.set_app_val.num_val = num_attrib;
3510 avrc_cmd.set_app_val.pdu = AVRC_PDU_SET_PLAYER_APP_VALUE;
3511 avrc_cmd.set_app_val.p_vals =
3512 (tAVRC_APP_SETTING *)osi_malloc(sizeof(tAVRC_APP_SETTING) * num_attrib);
3513 for (count = 0; count < num_attrib; count++)
3515 avrc_cmd.set_app_val.p_vals[count].attr_id = attrib_ids[count];
3516 avrc_cmd.set_app_val.p_vals[count].attr_val = attrib_vals[count];
3518 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3519 if ((status == AVRC_STS_NO_ERROR) && (p_msg != NULL))
3521 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3522 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3523 __FUNCTION__,p_transaction->lbl);
3524 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_CTRL,
3525 data_start, p_msg->len);
3526 status = BT_STATUS_SUCCESS;
3527 start_control_command_timer (AVRC_PDU_SET_PLAYER_APP_VALUE, p_transaction);
3531 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3532 __FUNCTION__, status);
3535 osi_free_and_reset((void **)&avrc_cmd.set_app_val.p_vals);
3537 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3542 /***************************************************************************
3544 ** Function get_player_app_setting_attr_text_cmd
3546 ** Description Get text description for app attribute
3550 ***************************************************************************/
3551 static bt_status_t get_player_app_setting_attr_text_cmd (UINT8 *attrs, UINT8 num_attrs)
3553 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3554 rc_transaction_t *p_transaction = NULL;
3556 #if (AVRC_CTLR_INCLUDED == TRUE)
3557 tAVRC_COMMAND avrc_cmd = {0};
3558 BT_HDR *p_msg = NULL;
3559 bt_status_t tran_status;
3562 BTIF_TRACE_DEBUG("%s: num attrs %d", __FUNCTION__, num_attrs);
3564 tran_status = get_transaction(&p_transaction);
3565 if (BT_STATUS_SUCCESS != tran_status)
3566 return BT_STATUS_FAIL;
3568 avrc_cmd.pdu = AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT;
3569 avrc_cmd.get_app_attr_txt.opcode = AVRC_OP_VENDOR;
3570 avrc_cmd.get_app_attr_txt.num_attr = num_attrs;
3572 for (count = 0; count < num_attrs; count++)
3574 avrc_cmd.get_app_attr_txt.attrs[count] = attrs[count];
3576 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3577 if (status == AVRC_STS_NO_ERROR)
3579 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3580 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3581 __FUNCTION__, p_transaction->lbl);
3582 BTA_AvVendorCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3583 AVRC_CMD_STATUS, data_start, p_msg->len);
3585 status = BT_STATUS_SUCCESS;
3586 start_status_command_timer (AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT, p_transaction);
3590 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x", __FUNCTION__, status);
3594 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3599 /***************************************************************************
3601 ** Function get_player_app_setting_val_text_cmd
3603 ** Description Get text description for app attribute values
3607 ***************************************************************************/
3608 static bt_status_t get_player_app_setting_value_text_cmd (UINT8 *vals, UINT8 num_vals)
3610 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3611 rc_transaction_t *p_transaction = NULL;
3613 #if (AVRC_CTLR_INCLUDED == TRUE)
3614 tAVRC_COMMAND avrc_cmd = {0};
3615 BT_HDR *p_msg = NULL;
3616 bt_status_t tran_status;
3619 BTIF_TRACE_DEBUG("%s: num_vals %d", __FUNCTION__, num_vals);
3621 tran_status = get_transaction(&p_transaction);
3622 if (BT_STATUS_SUCCESS != tran_status)
3623 return BT_STATUS_FAIL;
3625 avrc_cmd.pdu = AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT;
3626 avrc_cmd.get_app_val_txt.opcode = AVRC_OP_VENDOR;
3627 avrc_cmd.get_app_val_txt.num_val = num_vals;
3629 for (count = 0; count < num_vals; count++)
3631 avrc_cmd.get_app_val_txt.vals[count] = vals[count];
3633 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3634 if (status == AVRC_STS_NO_ERROR)
3636 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3637 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3638 __FUNCTION__, p_transaction->lbl);
3641 BTA_AvVendorCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3642 AVRC_CMD_STATUS, data_start, p_msg->len);
3643 status = BT_STATUS_SUCCESS;
3644 start_status_command_timer (AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT, p_transaction);
3649 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3650 __FUNCTION__, status);
3654 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3659 /***************************************************************************
3661 ** Function register_notification_cmd
3663 ** Description Send Command to register for a Notification ID
3667 ***************************************************************************/
3668 static bt_status_t register_notification_cmd (UINT8 label, UINT8 event_id, UINT32 event_value)
3671 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3672 #if (AVRC_CTLR_INCLUDED == TRUE)
3673 tAVRC_COMMAND avrc_cmd = {0};
3674 BT_HDR *p_msg = NULL;
3678 BTIF_TRACE_DEBUG("%s: event_id %d event_value", __FUNCTION__, event_id, event_value);
3680 avrc_cmd.reg_notif.opcode = AVRC_OP_VENDOR;
3681 avrc_cmd.reg_notif.status = AVRC_STS_NO_ERROR;
3682 avrc_cmd.reg_notif.event_id = event_id;
3683 avrc_cmd.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
3684 avrc_cmd.reg_notif.param = event_value;
3685 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3686 if (status == AVRC_STS_NO_ERROR)
3688 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3689 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3690 __FUNCTION__, label);
3693 BTA_AvVendorCmd(btif_rc_cb.rc_handle, label, AVRC_CMD_NOTIF,
3694 data_start, p_msg->len);
3695 status = BT_STATUS_SUCCESS;
3700 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3701 __FUNCTION__, status);
3705 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3710 /***************************************************************************
3712 ** Function get_element_attribute_cmd
3714 ** Description Get Element Attribute for attributeIds
3718 ***************************************************************************/
3719 static bt_status_t get_element_attribute_cmd (uint8_t num_attribute, uint32_t *p_attr_ids)
3721 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3722 rc_transaction_t *p_transaction=NULL;
3724 #if (AVRC_CTLR_INCLUDED == TRUE)
3725 tAVRC_COMMAND avrc_cmd = {0};
3726 BT_HDR *p_msg = NULL;
3727 bt_status_t tran_status;
3730 BTIF_TRACE_DEBUG("%s: num_attribute %d attribute_id %d",
3731 __FUNCTION__, num_attribute, p_attr_ids[0]);
3733 tran_status = get_transaction(&p_transaction);
3734 if (BT_STATUS_SUCCESS != tran_status)
3735 return BT_STATUS_FAIL;
3737 avrc_cmd.get_elem_attrs.opcode = AVRC_OP_VENDOR;
3738 avrc_cmd.get_elem_attrs.status = AVRC_STS_NO_ERROR;
3739 avrc_cmd.get_elem_attrs.num_attr = num_attribute;
3740 avrc_cmd.get_elem_attrs.pdu = AVRC_PDU_GET_ELEMENT_ATTR;
3741 for (count = 0; count < num_attribute; count++)
3743 avrc_cmd.get_elem_attrs.attrs[count] = p_attr_ids[count];
3746 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3747 if (status == AVRC_STS_NO_ERROR)
3749 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3750 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3751 __FUNCTION__, p_transaction->lbl);
3754 BTA_AvVendorCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3755 AVRC_CMD_STATUS, data_start, p_msg->len);
3756 status = BT_STATUS_SUCCESS;
3757 start_status_command_timer (AVRC_PDU_GET_ELEMENT_ATTR,
3763 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3764 __FUNCTION__, status);
3768 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3773 /***************************************************************************
3775 ** Function get_play_status_cmd
3777 ** Description Get Element Attribute for attributeIds
3781 ***************************************************************************/
3782 static bt_status_t get_play_status_cmd(void)
3784 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3785 rc_transaction_t *p_transaction = NULL;
3786 #if (AVRC_CTLR_INCLUDED == TRUE)
3787 tAVRC_COMMAND avrc_cmd = {0};
3788 BT_HDR *p_msg = NULL;
3789 bt_status_t tran_status;
3792 BTIF_TRACE_DEBUG("%s: ", __FUNCTION__);
3793 tran_status = get_transaction(&p_transaction);
3794 if (BT_STATUS_SUCCESS != tran_status)
3795 return BT_STATUS_FAIL;
3797 avrc_cmd.get_play_status.opcode = AVRC_OP_VENDOR;
3798 avrc_cmd.get_play_status.pdu = AVRC_PDU_GET_PLAY_STATUS;
3799 avrc_cmd.get_play_status.status = AVRC_STS_NO_ERROR;
3800 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3801 if (status == AVRC_STS_NO_ERROR)
3803 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3804 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3805 __FUNCTION__, p_transaction->lbl);
3808 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,
3809 AVRC_CMD_STATUS, data_start, p_msg->len);
3810 status = BT_STATUS_SUCCESS;
3811 start_status_command_timer (AVRC_PDU_GET_PLAY_STATUS, p_transaction);
3816 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3817 __FUNCTION__, status);
3821 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3827 /***************************************************************************
3829 ** Function set_volume_rsp
3831 ** Description Rsp for SetAbsoluteVolume Command
3835 ***************************************************************************/
3836 static bt_status_t set_volume_rsp(bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label)
3838 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3839 #if (AVRC_CTLR_INCLUDED == TRUE)
3840 tAVRC_RESPONSE avrc_rsp;
3841 BT_HDR *p_msg = NULL;
3844 BTIF_TRACE_DEBUG("%s: abs_vol %d", __FUNCTION__, abs_vol);
3846 avrc_rsp.volume.opcode = AVRC_OP_VENDOR;
3847 avrc_rsp.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME;
3848 avrc_rsp.volume.status = AVRC_STS_NO_ERROR;
3849 avrc_rsp.volume.volume = abs_vol;
3850 status = AVRC_BldResponse(btif_rc_cb.rc_handle, &avrc_rsp, &p_msg);
3851 if (status == AVRC_STS_NO_ERROR)
3853 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3854 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3855 __FUNCTION__, btif_rc_cb.rc_vol_label);
3858 BTA_AvVendorRsp(btif_rc_cb.rc_handle, label,
3859 BTA_AV_RSP_ACCEPT, data_start, p_msg->len, 0);
3860 status = BT_STATUS_SUCCESS;
3865 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3866 __FUNCTION__, status);
3870 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3875 /***************************************************************************
3877 ** Function send_register_abs_vol_rsp
3879 ** Description Rsp for Notification of Absolute Volume
3883 ***************************************************************************/
3884 static bt_status_t volume_change_notification_rsp(bt_bdaddr_t *bd_addr, btrc_notification_type_t rsp_type,
3885 uint8_t abs_vol, uint8_t label)
3887 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3888 tAVRC_RESPONSE avrc_rsp;
3889 BT_HDR *p_msg = NULL;
3890 #if (AVRC_CTLR_INCLUDED == TRUE)
3891 BTIF_TRACE_DEBUG("%s: rsp_type %d abs_vol %d", __func__, rsp_type, abs_vol);
3894 avrc_rsp.reg_notif.opcode = AVRC_OP_VENDOR;
3895 avrc_rsp.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
3896 avrc_rsp.reg_notif.status = AVRC_STS_NO_ERROR;
3897 avrc_rsp.reg_notif.param.volume = abs_vol;
3898 avrc_rsp.reg_notif.event_id = AVRC_EVT_VOLUME_CHANGE;
3900 status = AVRC_BldResponse(btif_rc_cb.rc_handle, &avrc_rsp, &p_msg);
3901 if (status == AVRC_STS_NO_ERROR) {
3902 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3904 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3905 BTA_AvVendorRsp(btif_rc_cb.rc_handle, label,
3906 (rsp_type == BTRC_NOTIFICATION_TYPE_INTERIM) ?
3907 AVRC_RSP_INTERIM : AVRC_RSP_CHANGED,
3908 data_start, p_msg->len, 0);
3909 status = BT_STATUS_SUCCESS;
3911 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3917 BTIF_TRACE_DEBUG("%s: feature not enabled", __func__);
3922 /***************************************************************************
3924 ** Function send_groupnavigation_cmd
3926 ** Description Send Pass-Through command
3930 ***************************************************************************/
3931 static bt_status_t send_groupnavigation_cmd(bt_bdaddr_t *bd_addr, uint8_t key_code,
3934 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3935 #if (AVRC_CTLR_INCLUDED == TRUE)
3936 rc_transaction_t *p_transaction=NULL;
3937 BTIF_TRACE_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
3938 key_code, key_state);
3940 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
3942 bt_status_t tran_status = get_transaction(&p_transaction);
3943 if ((BT_STATUS_SUCCESS == tran_status) && (NULL != p_transaction)) {
3944 UINT8 buffer[AVRC_PASS_THRU_GROUP_LEN] = {0};
3945 UINT8* start = buffer;
3946 UINT24_TO_BE_STREAM(start, AVRC_CO_METADATA);
3948 UINT8_TO_BE_STREAM(start, key_code);
3949 BTA_AvRemoteVendorUniqueCmd(btif_rc_cb.rc_handle,
3951 (tBTA_AV_STATE)key_state, buffer,
3952 AVRC_PASS_THRU_GROUP_LEN);
3953 status = BT_STATUS_SUCCESS;
3954 BTIF_TRACE_DEBUG("%s: succesfully sent group_navigation command to BTA",
3959 status = BT_STATUS_FAIL;
3960 BTIF_TRACE_DEBUG("%s: error in fetching transaction", __FUNCTION__);
3965 status = BT_STATUS_FAIL;
3966 BTIF_TRACE_DEBUG("%s: feature not supported", __FUNCTION__);
3969 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3974 /***************************************************************************
3976 ** Function send_passthrough_cmd
3978 ** Description Send Pass-Through command
3982 ***************************************************************************/
3983 static bt_status_t send_passthrough_cmd(bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state)
3985 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3986 #if (AVRC_CTLR_INCLUDED == TRUE)
3988 rc_transaction_t *p_transaction=NULL;
3989 BTIF_TRACE_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
3990 key_code, key_state);
3991 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
3993 bt_status_t tran_status = get_transaction(&p_transaction);
3994 if (BT_STATUS_SUCCESS == tran_status && NULL != p_transaction)
3996 BTA_AvRemoteCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3997 (tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state);
3998 status = BT_STATUS_SUCCESS;
3999 BTIF_TRACE_DEBUG("%s: succesfully sent passthrough command to BTA", __FUNCTION__);
4003 status = BT_STATUS_FAIL;
4004 BTIF_TRACE_DEBUG("%s: error in fetching transaction", __FUNCTION__);
4009 status = BT_STATUS_FAIL;
4010 BTIF_TRACE_DEBUG("%s: feature not supported", __FUNCTION__);
4013 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
4018 static const btrc_interface_t bt_rc_interface = {
4019 sizeof(bt_rc_interface),
4021 get_play_status_rsp,
4022 NULL, /* list_player_app_attr_rsp */
4023 NULL, /* list_player_app_value_rsp */
4024 NULL, /* get_player_app_value_rsp */
4025 NULL, /* get_player_app_attr_text_rsp */
4026 NULL, /* get_player_app_value_text_rsp */
4027 get_element_attr_rsp,
4028 NULL, /* set_player_app_value_rsp */
4029 register_notification_rsp,
4034 static const btrc_ctrl_interface_t bt_rc_ctrl_interface = {
4035 sizeof(bt_rc_ctrl_interface),
4037 send_passthrough_cmd,
4038 send_groupnavigation_cmd,
4039 change_player_app_setting,
4041 volume_change_notification_rsp,
4045 /*******************************************************************************
4047 ** Function btif_rc_get_interface
4049 ** Description Get the AVRCP Target callback interface
4051 ** Returns btav_interface_t
4053 *******************************************************************************/
4054 const btrc_interface_t *btif_rc_get_interface(void)
4056 BTIF_TRACE_EVENT("%s", __FUNCTION__);
4057 return &bt_rc_interface;
4060 /*******************************************************************************
4062 ** Function btif_rc_ctrl_get_interface
4064 ** Description Get the AVRCP Controller callback interface
4066 ** Returns btav_interface_t
4068 *******************************************************************************/
4069 const btrc_ctrl_interface_t *btif_rc_ctrl_get_interface(void)
4071 BTIF_TRACE_EVENT("%s", __FUNCTION__);
4072 return &bt_rc_ctrl_interface;
4075 /*******************************************************************************
4076 ** Function initialize_transaction
4078 ** Description Initializes fields of the transaction structure
4081 *******************************************************************************/
4082 static void initialize_transaction(int lbl)
4084 pthread_mutex_lock(&device.lbllock);
4085 if (lbl < MAX_TRANSACTIONS_PER_SESSION) {
4086 if (alarm_is_scheduled(device.transaction[lbl].txn_timer)) {
4087 clear_cmd_timeout(lbl);
4089 device.transaction[lbl].lbl = lbl;
4090 device.transaction[lbl].in_use=FALSE;
4091 device.transaction[lbl].handle=0;
4093 pthread_mutex_unlock(&device.lbllock);
4096 /*******************************************************************************
4097 ** Function lbl_init
4099 ** Description Initializes label structures and mutexes.
4102 *******************************************************************************/
4105 memset(&device,0,sizeof(rc_device_t));
4106 pthread_mutexattr_t attr;
4107 pthread_mutexattr_init(&attr);
4108 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
4109 pthread_mutex_init(&(device.lbllock), &attr);
4110 pthread_mutexattr_destroy(&attr);
4111 init_all_transactions();
4114 /*******************************************************************************
4116 ** Function init_all_transactions
4118 ** Description Initializes all transactions
4121 *******************************************************************************/
4122 void init_all_transactions()
4125 for(txn_indx=0; txn_indx < MAX_TRANSACTIONS_PER_SESSION; txn_indx++)
4127 initialize_transaction(txn_indx);
4131 /*******************************************************************************
4133 ** Function get_transaction_by_lbl
4135 ** Description Will return a transaction based on the label. If not inuse
4136 ** will return an error.
4138 ** Returns bt_status_t
4139 *******************************************************************************/
4140 rc_transaction_t *get_transaction_by_lbl(UINT8 lbl)
4142 rc_transaction_t *transaction = NULL;
4143 pthread_mutex_lock(&device.lbllock);
4145 /* Determine if this is a valid label */
4146 if (lbl < MAX_TRANSACTIONS_PER_SESSION)
4148 if (FALSE==device.transaction[lbl].in_use)
4154 transaction = &(device.transaction[lbl]);
4155 BTIF_TRACE_DEBUG("%s: Got transaction.label: %d",__FUNCTION__,lbl);
4159 pthread_mutex_unlock(&device.lbllock);
4163 /*******************************************************************************
4165 ** Function get_transaction
4167 ** Description Obtains the transaction details.
4169 ** Returns bt_status_t
4170 *******************************************************************************/
4172 bt_status_t get_transaction(rc_transaction_t **ptransaction)
4174 bt_status_t result = BT_STATUS_NOMEM;
4176 pthread_mutex_lock(&device.lbllock);
4178 // Check for unused transactions
4179 for (i=0; i<MAX_TRANSACTIONS_PER_SESSION; i++)
4181 if (FALSE==device.transaction[i].in_use)
4183 BTIF_TRACE_DEBUG("%s:Got transaction.label: %d",__FUNCTION__,device.transaction[i].lbl);
4184 device.transaction[i].in_use = TRUE;
4185 *ptransaction = &(device.transaction[i]);
4186 result = BT_STATUS_SUCCESS;
4191 pthread_mutex_unlock(&device.lbllock);
4195 /*******************************************************************************
4197 ** Function release_transaction
4199 ** Description Will release a transaction for reuse
4201 ** Returns bt_status_t
4202 *******************************************************************************/
4203 void release_transaction(UINT8 lbl)
4205 rc_transaction_t *transaction = get_transaction_by_lbl(lbl);
4207 /* If the transaction is in use... */
4208 if (transaction != NULL)
4210 BTIF_TRACE_DEBUG("%s: lbl: %d", __FUNCTION__, lbl);
4211 initialize_transaction(lbl);
4215 /*******************************************************************************
4217 ** Function lbl_destroy
4219 ** Description Cleanup of the mutex
4222 *******************************************************************************/
4225 pthread_mutex_destroy(&(device.lbllock));
4228 /*******************************************************************************
4229 ** Function sleep_ms
4231 ** Description Sleep the calling thread unconditionally for
4232 ** |timeout_ms| milliseconds.
4235 *******************************************************************************/
4236 static void sleep_ms(period_ms_t timeout_ms) {
4237 struct timespec delay;
4238 delay.tv_sec = timeout_ms / 1000;
4239 delay.tv_nsec = 1000 * 1000 * (timeout_ms % 1000);
4243 err = nanosleep(&delay, &delay);
4244 } while (err == -1 && errno == EINTR);
4247 static bool absolute_volume_disabled() {
4248 char volume_disabled[PROPERTY_VALUE_MAX] = {0};
4249 osi_property_get("persist.bluetooth.disableabsvol", volume_disabled, "false");
4250 if (strncmp(volume_disabled, "true", 4) == 0) {
4251 BTIF_TRACE_WARNING("%s: Absolute volume disabled by property", __func__);