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"
47 #include "osi/include/list.h"
48 #include "osi/include/properties.h"
50 #define RC_INVALID_TRACK_ID (0xFFFFFFFFFFFFFFFFULL)
52 /*****************************************************************************
54 ******************************************************************************/
56 /* cod value for Headsets */
57 #define COD_AV_HEADSETS 0x0404
58 /* for AVRC 1.4 need to change this */
59 #define MAX_RC_NOTIFICATIONS AVRC_EVT_VOLUME_CHANGE
61 #define IDX_GET_PLAY_STATUS_RSP 0
62 #define IDX_LIST_APP_ATTR_RSP 1
63 #define IDX_LIST_APP_VALUE_RSP 2
64 #define IDX_GET_CURR_APP_VAL_RSP 3
65 #define IDX_SET_APP_VAL_RSP 4
66 #define IDX_GET_APP_ATTR_TXT_RSP 5
67 #define IDX_GET_APP_VAL_TXT_RSP 6
68 #define IDX_GET_ELEMENT_ATTR_RSP 7
69 #define MAX_VOLUME 128
71 #define MAX_TRANSACTIONS_PER_SESSION 16
72 #define MAX_CMD_QUEUE_LEN 8
73 #define PLAY_STATUS_PLAYING 1
75 #define CHECK_RC_CONNECTED \
76 BTIF_TRACE_DEBUG("## %s ##", __FUNCTION__); \
77 if (btif_rc_cb.rc_connected == FALSE) \
79 BTIF_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \
80 return BT_STATUS_NOT_READY; \
83 #define FILL_PDU_QUEUE(index, ctype, label, pending) \
85 btif_rc_cb.rc_pdu_info[index].ctype = ctype; \
86 btif_rc_cb.rc_pdu_info[index].label = label; \
87 btif_rc_cb.rc_pdu_info[index].is_rsp_pending = pending; \
90 #define SEND_METAMSG_RSP(index, avrc_rsp) \
92 if (btif_rc_cb.rc_pdu_info[index].is_rsp_pending == FALSE) \
94 BTIF_TRACE_WARNING("%s Not sending response as no PDU was registered", __FUNCTION__); \
95 return BT_STATUS_UNHANDLED; \
97 send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_pdu_info[index].label, \
98 btif_rc_cb.rc_pdu_info[index].ctype, avrc_rsp); \
99 btif_rc_cb.rc_pdu_info[index].ctype = 0; \
100 btif_rc_cb.rc_pdu_info[index].label = 0; \
101 btif_rc_cb.rc_pdu_info[index].is_rsp_pending = FALSE; \
104 /*****************************************************************************
105 ** Local type definitions
106 ******************************************************************************/
110 } btif_rc_reg_notifications_t;
116 BOOLEAN is_rsp_pending;
117 } btif_rc_cmd_ctxt_t;
119 /* 2 second timeout to get interim response */
120 #define BTIF_TIMEOUT_RC_INTERIM_RSP_MS (2 * 1000)
121 #define BTIF_TIMEOUT_RC_STATUS_CMD_MS (2 * 1000)
122 #define BTIF_TIMEOUT_RC_CONTROL_CMD_MS (2 * 1000)
130 } btif_rc_nfn_reg_status_t;
135 btif_rc_nfn_reg_status_t status;
136 } btif_rc_supported_event_t;
138 #define BTIF_RC_STS_TIMEOUT 0xFE
142 } btif_rc_status_cmd_timer_t;
147 } btif_rc_control_cmd_timer_t;
151 btif_rc_status_cmd_timer_t rc_status_cmd;
152 btif_rc_control_cmd_timer_t rc_control_cmd;
154 } btif_rc_timer_context_t;
157 BOOLEAN query_started;
162 UINT8 ext_attr_index;
164 btrc_player_app_attr_t attrs[AVRC_MAX_APP_ATTR_SIZE];
165 btrc_player_app_ext_attr_t ext_attrs[AVRC_MAX_APP_ATTR_SIZE];
166 } btif_rc_player_app_settings_t;
168 /* TODO : Merge btif_rc_reg_notifications_t and btif_rc_cmd_ctxt_t to a single struct */
170 BOOLEAN rc_connected;
172 tBTA_AV_FEAT rc_features;
174 UINT16 rc_pending_play;
175 btif_rc_cmd_ctxt_t rc_pdu_info[MAX_CMD_QUEUE_LEN];
176 btif_rc_reg_notifications_t rc_notif[MAX_RC_NOTIFICATIONS];
177 unsigned int rc_volume;
178 uint8_t rc_vol_label;
179 list_t *rc_supported_event_list;
180 btif_rc_player_app_settings_t rc_app_settings;
181 alarm_t *rc_play_status_timer;
182 BOOLEAN rc_features_processed;
183 UINT64 rc_playing_uid;
184 BOOLEAN rc_procedure_complete;
191 btif_rc_timer_context_t txn_timer_context;
197 pthread_mutex_t lbllock;
198 rc_transaction_t transaction[MAX_TRANSACTIONS_PER_SESSION];
203 #define MAX_UINPUT_PATHS 3
204 static const char* uinput_dev_path[] =
205 {"/dev/uinput", "/dev/input/uinput", "/dev/misc/uinput" };
206 static int uinput_fd = -1;
208 static int send_event (int fd, uint16_t type, uint16_t code, int32_t value);
209 static void send_key (int fd, uint16_t key, int pressed);
210 static int uinput_driver_check();
211 static int uinput_create(char *name);
212 static int init_uinput (void);
213 static void close_uinput (void);
214 static void sleep_ms(period_ms_t timeout_ms);
216 static const struct {
220 uint8_t release_quirk;
222 { "PLAY", AVRC_ID_PLAY, KEY_PLAYCD, 1 },
223 { "STOP", AVRC_ID_STOP, KEY_STOPCD, 0 },
224 { "PAUSE", AVRC_ID_PAUSE, KEY_PAUSECD, 1 },
225 { "FORWARD", AVRC_ID_FORWARD, KEY_NEXTSONG, 0 },
226 { "BACKWARD", AVRC_ID_BACKWARD, KEY_PREVIOUSSONG, 0 },
227 { "REWIND", AVRC_ID_REWIND, KEY_REWIND, 0 },
228 { "FAST FORWARD", AVRC_ID_FAST_FOR, KEY_FAST_FORWARD, 0 },
232 static void send_reject_response (UINT8 rc_handle, UINT8 label,
233 UINT8 pdu, UINT8 status);
234 static UINT8 opcode_from_pdu(UINT8 pdu);
235 static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label,
236 tBTA_AV_CODE code, tAVRC_RESPONSE *pmetamsg_resp);
237 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
238 static void register_volumechange(UINT8 label);
240 static void lbl_init();
241 static void lbl_destroy();
242 static void init_all_transactions();
243 static bt_status_t get_transaction(rc_transaction_t **ptransaction);
244 static void release_transaction(UINT8 label);
245 static rc_transaction_t* get_transaction_by_lbl(UINT8 label);
246 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
247 static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg);
249 #if (AVRC_CTLR_INCLUDED == TRUE)
250 static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG *pmeta_msg);
251 static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg);
252 static void btif_rc_ctrl_upstreams_rsp_cmd(
253 UINT8 event, tAVRC_COMMAND *pavrc_cmd, UINT8 label);
254 static void rc_ctrl_procedure_complete();
255 static void rc_stop_play_status_timer();
256 static void register_for_event_notification (btif_rc_supported_event_t *p_event);
257 static void handle_get_capability_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CAPS_RSP *p_rsp);
258 static void handle_app_attr_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_ATTR_RSP *p_rsp);
259 static void handle_app_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_VALUES_RSP *p_rsp);
260 static void handle_app_cur_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp);
261 static void handle_app_attr_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp);
262 static void handle_app_attr_val_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp);
263 static void handle_get_playstatus_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_PLAY_STATUS_RSP *p_rsp);
264 static void handle_get_elem_attr_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_ELEM_ATTRS_RSP *p_rsp);
265 static void handle_set_app_attr_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_RSP *p_rsp);
266 static bt_status_t get_play_status_cmd(void);
267 static bt_status_t get_player_app_setting_attr_text_cmd (UINT8 *attrs, UINT8 num_attrs);
268 static bt_status_t get_player_app_setting_value_text_cmd (UINT8 *vals, UINT8 num_vals);
269 static bt_status_t register_notification_cmd (UINT8 label, UINT8 event_id, UINT32 event_value);
270 static bt_status_t get_element_attribute_cmd (uint8_t num_attribute, uint32_t *p_attr_ids);
271 static bt_status_t getcapabilities_cmd (uint8_t cap_id);
272 static bt_status_t list_player_app_setting_attrib_cmd(void);
273 static bt_status_t list_player_app_setting_value_cmd(uint8_t attrib_id);
274 static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib, uint8_t* attrib_ids);
276 static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND* p_param, UINT8 ctype, UINT8 label);
277 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
278 static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label);
280 static void rc_start_play_status_timer(void);
281 static bool absolute_volume_disabled(void);
282 static char const* key_id_to_str(uint16_t id);
284 /*****************************************************************************
286 ******************************************************************************/
287 static btif_rc_cb_t btif_rc_cb;
288 static btrc_callbacks_t *bt_rc_callbacks = NULL;
289 static btrc_ctrl_callbacks_t *bt_rc_ctrl_callbacks = NULL;
291 /*****************************************************************************
293 ******************************************************************************/
295 /*****************************************************************************
297 ******************************************************************************/
298 extern BOOLEAN btif_hf_call_terminated_recently();
299 extern BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod);
301 extern fixed_queue_t *btu_general_alarm_queue;
303 /*****************************************************************************
305 ******************************************************************************/
307 /*****************************************************************************
308 ** Local uinput helper functions
309 ******************************************************************************/
310 int send_event (int fd, uint16_t type, uint16_t code, int32_t value)
312 struct uinput_event event;
313 BTIF_TRACE_DEBUG("%s type:%u code:%u value:%d", __FUNCTION__,
315 memset(&event, 0, sizeof(event));
321 OSI_NO_INTR(ret = write(fd, &event, sizeof(event)));
325 void send_key (int fd, uint16_t key, int pressed)
327 BTIF_TRACE_DEBUG("%s fd:%d key:%u pressed:%d", __FUNCTION__,
335 LOG_INFO(LOG_TAG, "AVRCP: Send key %s (%d) fd=%d", key_id_to_str(key), pressed, fd);
336 send_event(fd, EV_KEY, key, pressed);
337 send_event(fd, EV_SYN, SYN_REPORT, 0);
340 /************** uinput related functions **************/
341 int uinput_driver_check()
344 for (i=0; i < MAX_UINPUT_PATHS; i++)
346 if (access(uinput_dev_path[i], O_RDWR) == 0) {
350 BTIF_TRACE_ERROR("%s ERROR: uinput device is not in the system", __FUNCTION__);
354 int uinput_create(char *name)
356 struct uinput_dev dev;
359 for(x=0; x < MAX_UINPUT_PATHS; x++)
361 fd = open(uinput_dev_path[x], O_RDWR);
366 if (x == MAX_UINPUT_PATHS) {
367 BTIF_TRACE_ERROR("%s ERROR: uinput device open failed", __FUNCTION__);
370 memset(&dev, 0, sizeof(dev));
372 strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE-1);
374 dev.id.bustype = BUS_BLUETOOTH;
375 dev.id.vendor = 0x0000;
376 dev.id.product = 0x0000;
377 dev.id.version = 0x0000;
380 OSI_NO_INTR(ret = write(fd, &dev, sizeof(dev)));
382 BTIF_TRACE_ERROR("%s Unable to write device information", __FUNCTION__);
387 ioctl(fd, UI_SET_EVBIT, EV_KEY);
388 ioctl(fd, UI_SET_EVBIT, EV_REL);
389 ioctl(fd, UI_SET_EVBIT, EV_SYN);
391 for (x = 0; key_map[x].name != NULL; x++)
392 ioctl(fd, UI_SET_KEYBIT, key_map[x].mapped_id);
394 if (ioctl(fd, UI_DEV_CREATE, NULL) < 0) {
395 BTIF_TRACE_ERROR("%s Unable to create uinput device", __FUNCTION__);
402 int init_uinput (void)
404 char *name = "AVRCP";
406 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
407 uinput_fd = uinput_create(name);
409 BTIF_TRACE_ERROR("%s AVRCP: Failed to initialize uinput for %s (%d)",
410 __FUNCTION__, name, uinput_fd);
412 BTIF_TRACE_DEBUG("%s AVRCP: Initialized uinput for %s (fd=%d)",
413 __FUNCTION__, name, uinput_fd);
418 void close_uinput (void)
420 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
422 ioctl(uinput_fd, UI_DEV_DESTROY);
429 #if (AVRC_CTLR_INCLUDED == TRUE)
430 void rc_cleanup_sent_cmd (void *p_data)
432 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
436 void handle_rc_ctrl_features(BD_ADDR bd_addr)
438 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)||
439 ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCCT)&&
440 (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL)))
444 bdcpy(rc_addr.address,bd_addr);
446 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL)&&
447 (btif_rc_cb.rc_features & BTA_AV_FEAT_RCCT))
449 rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME;
451 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_METADATA)&&
452 (btif_rc_cb.rc_features & BTA_AV_FEAT_VENDOR)&&
453 (btif_rc_cb.rc_features_processed != TRUE))
455 rc_features |= BTRC_FEAT_METADATA;
456 /* Mark rc features processed to avoid repeating
457 * the AVRCP procedure every time on receiving this
460 btif_rc_cb.rc_features_processed = TRUE;
462 if (btif_av_is_sink_enabled())
463 getcapabilities_cmd (AVRC_CAP_COMPANY_ID);
465 BTIF_TRACE_DEBUG("%s Update rc features to CTRL %d", __FUNCTION__, rc_features);
466 HAL_CBACK(bt_rc_ctrl_callbacks, getrcfeatures_cb, &rc_addr, rc_features);
471 void handle_rc_features(BD_ADDR bd_addr)
473 if (bt_rc_callbacks != NULL)
475 btrc_remote_features_t rc_features = BTRC_FEAT_NONE;
478 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
479 bt_bdaddr_t avdtp_addr = btif_av_get_addr();
481 bdstr_t addr1, addr2;
482 BTIF_TRACE_DEBUG("%s: AVDTP Address: %s AVCTP address: %s", __func__,
483 bdaddr_to_string(&avdtp_addr, addr1, sizeof(addr1)),
484 bdaddr_to_string(&rc_addr, addr2, sizeof(addr2)));
486 if (interop_match_addr(INTEROP_DISABLE_ABSOLUTE_VOLUME, &rc_addr)
487 || absolute_volume_disabled()
488 || bdcmp(avdtp_addr.address, rc_addr.address))
489 btif_rc_cb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
491 if (btif_rc_cb.rc_features & BTA_AV_FEAT_BROWSE)
493 rc_features |= BTRC_FEAT_BROWSE;
496 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
497 if ( (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL) &&
498 (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG))
500 rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME;
504 if (btif_rc_cb.rc_features & BTA_AV_FEAT_METADATA)
506 rc_features |= BTRC_FEAT_METADATA;
509 BTIF_TRACE_DEBUG("%s: rc_features=0x%x", __FUNCTION__, rc_features);
510 HAL_CBACK(bt_rc_callbacks, remote_features_cb, &rc_addr, rc_features)
512 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
513 BTIF_TRACE_DEBUG("%s Checking for feature flags in btif_rc_handler with label %d",
514 __FUNCTION__, btif_rc_cb.rc_vol_label);
515 // Register for volume change on connect
516 if (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL &&
517 btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
519 rc_transaction_t *p_transaction=NULL;
520 bt_status_t status = BT_STATUS_NOT_READY;
521 if (MAX_LABEL==btif_rc_cb.rc_vol_label)
523 status=get_transaction(&p_transaction);
527 p_transaction=get_transaction_by_lbl(btif_rc_cb.rc_vol_label);
528 if (NULL!=p_transaction)
530 BTIF_TRACE_DEBUG("%s register_volumechange already in progress for label %d",
531 __FUNCTION__, btif_rc_cb.rc_vol_label);
535 status=get_transaction(&p_transaction);
538 if (BT_STATUS_SUCCESS == status && NULL!=p_transaction)
540 btif_rc_cb.rc_vol_label=p_transaction->lbl;
541 register_volumechange(btif_rc_cb.rc_vol_label);
548 /***************************************************************************
549 * Function handle_rc_connect
551 * - Argument: tBTA_AV_RC_OPEN RC open data structure
553 * - Description: RC connection event handler
555 ***************************************************************************/
556 void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
558 BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle);
559 bt_status_t result = BT_STATUS_SUCCESS;
560 #if (AVRC_CTLR_INCLUDED == TRUE)
564 if (p_rc_open->status == BTA_AV_SUCCESS)
566 //check if already some RC is connected
567 if (btif_rc_cb.rc_connected)
569 BTIF_TRACE_ERROR("%s Got RC OPEN in connected state, Connected RC: %d \
570 and Current RC: %d", __FUNCTION__, btif_rc_cb.rc_handle,p_rc_open->rc_handle );
571 if ((btif_rc_cb.rc_handle != p_rc_open->rc_handle)
572 && (bdcmp(btif_rc_cb.rc_addr, p_rc_open->peer_addr)))
574 BTIF_TRACE_DEBUG("%s Got RC connected for some other handle", __FUNCTION__);
575 BTA_AvCloseRc(p_rc_open->rc_handle);
579 memcpy(btif_rc_cb.rc_addr, p_rc_open->peer_addr, sizeof(BD_ADDR));
580 btif_rc_cb.rc_features = p_rc_open->peer_features;
581 btif_rc_cb.rc_vol_label=MAX_LABEL;
582 btif_rc_cb.rc_volume=MAX_VOLUME;
584 btif_rc_cb.rc_connected = TRUE;
585 btif_rc_cb.rc_handle = p_rc_open->rc_handle;
587 /* on locally initiated connection we will get remote features as part of connect */
588 if (btif_rc_cb.rc_features != 0)
589 handle_rc_features(btif_rc_cb.rc_addr);
592 result = uinput_driver_check();
593 if (result == BT_STATUS_SUCCESS)
600 BTIF_TRACE_WARNING("%s Avrcp TG role not enabled, not initializing UInput",
603 BTIF_TRACE_DEBUG("%s handle_rc_connect features %d ",__FUNCTION__, btif_rc_cb.rc_features);
604 #if (AVRC_CTLR_INCLUDED == TRUE)
605 btif_rc_cb.rc_playing_uid = RC_INVALID_TRACK_ID;
606 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
607 if (bt_rc_ctrl_callbacks != NULL)
609 HAL_CBACK(bt_rc_ctrl_callbacks, connection_state_cb, TRUE, &rc_addr);
611 /* report connection state if remote device is AVRCP target */
612 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)||
613 ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCCT)&&
614 (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL)))
616 handle_rc_ctrl_features(btif_rc_cb.rc_addr);
622 BTIF_TRACE_ERROR("%s Connect failed with error code: %d",
623 __FUNCTION__, p_rc_open->status);
624 btif_rc_cb.rc_connected = FALSE;
628 /***************************************************************************
629 * Function handle_rc_disconnect
631 * - Argument: tBTA_AV_RC_CLOSE RC close data structure
633 * - Description: RC disconnection event handler
635 ***************************************************************************/
636 void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
638 #if (AVRC_CTLR_INCLUDED == TRUE)
640 tBTA_AV_FEAT features;
642 BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_close->rc_handle);
643 if ((p_rc_close->rc_handle != btif_rc_cb.rc_handle)
644 && (bdcmp(btif_rc_cb.rc_addr, p_rc_close->peer_addr)))
646 BTIF_TRACE_ERROR("Got disconnect of unknown device");
649 #if (AVRC_CTLR_INCLUDED == TRUE)
650 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
651 features = btif_rc_cb.rc_features;
652 /* Clean up AVRCP procedure flags */
653 memset(&btif_rc_cb.rc_app_settings, 0,
654 sizeof(btif_rc_player_app_settings_t));
655 btif_rc_cb.rc_features_processed = FALSE;
656 btif_rc_cb.rc_procedure_complete = FALSE;
657 rc_stop_play_status_timer();
658 /* Check and clear the notification event list */
659 if (btif_rc_cb.rc_supported_event_list != NULL)
661 list_clear(btif_rc_cb.rc_supported_event_list);
662 btif_rc_cb.rc_supported_event_list = NULL;
665 btif_rc_cb.rc_handle = 0;
666 btif_rc_cb.rc_connected = FALSE;
667 memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
668 memset(btif_rc_cb.rc_notif, 0, sizeof(btif_rc_cb.rc_notif));
670 btif_rc_cb.rc_features = 0;
671 btif_rc_cb.rc_vol_label=MAX_LABEL;
672 btif_rc_cb.rc_volume=MAX_VOLUME;
673 init_all_transactions();
674 if (bt_rc_callbacks != NULL)
680 BTIF_TRACE_WARNING("%s Avrcp TG role not enabled, not closing UInput", __FUNCTION__);
683 memset(btif_rc_cb.rc_addr, 0, sizeof(BD_ADDR));
684 #if (AVRC_CTLR_INCLUDED == TRUE)
685 /* report connection state if device is AVRCP target */
686 if (bt_rc_ctrl_callbacks != NULL)
688 HAL_CBACK(bt_rc_ctrl_callbacks, connection_state_cb, FALSE, &rc_addr);
693 /***************************************************************************
694 * Function handle_rc_passthrough_cmd
696 * - Argument: tBTA_AV_RC rc_id remote control command ID
697 * tBTA_AV_STATE key_state status of key press
699 * - Description: Remote control command handler
701 ***************************************************************************/
702 void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
707 BTIF_TRACE_DEBUG("%s: p_remote_cmd->rc_id=%d", __FUNCTION__, p_remote_cmd->rc_id);
709 /* If AVRC is open and peer sends PLAY but there is no AVDT, then we queue-up this PLAY */
712 /* queue AVRC PLAY if GAVDTP Open notification to app is pending (2 second timer) */
713 if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY) && (!btif_av_is_connected()))
715 if (p_remote_cmd->key_state == AVRC_STATE_PRESS)
717 APPL_TRACE_WARNING("%s: AVDT not open, queuing the PLAY command", __FUNCTION__);
718 btif_rc_cb.rc_pending_play = TRUE;
723 if ((p_remote_cmd->rc_id == BTA_AV_RC_PAUSE) && (btif_rc_cb.rc_pending_play))
725 APPL_TRACE_WARNING("%s: Clear the pending PLAY on PAUSE received", __FUNCTION__);
726 btif_rc_cb.rc_pending_play = FALSE;
729 if ((p_remote_cmd->rc_id == BTA_AV_RC_VOL_UP)||(p_remote_cmd->rc_id == BTA_AV_RC_VOL_DOWN))
730 return; // this command is not to be sent to UINPUT, only needed for PTS
733 if ((p_remote_cmd->rc_id == BTA_AV_RC_STOP) && (!btif_av_stream_started_ready()))
735 APPL_TRACE_WARNING("%s: Stream suspended, ignore STOP cmd",__FUNCTION__);
739 if (p_remote_cmd->key_state == AVRC_STATE_RELEASE) {
747 if (p_remote_cmd->rc_id == BTA_AV_RC_FAST_FOR || p_remote_cmd->rc_id == BTA_AV_RC_REWIND) {
748 HAL_CBACK(bt_rc_callbacks, passthrough_cmd_cb, p_remote_cmd->rc_id, pressed);
752 for (i = 0; key_map[i].name != NULL; i++) {
753 if (p_remote_cmd->rc_id == key_map[i].avrcp) {
754 BTIF_TRACE_DEBUG("%s: %s %s", __FUNCTION__, key_map[i].name, status);
756 /* MusicPlayer uses a long_press_timeout of 1 second for PLAYPAUSE button
757 * and maps that to autoshuffle. So if for some reason release for PLAY/PAUSE
758 * comes 1 second after the press, the MediaPlayer UI goes into a bad state.
759 * The reason for the delay could be sniff mode exit or some AVDTP procedure etc.
760 * The fix is to generate a release right after the press and drown the 'actual'
763 if ((key_map[i].release_quirk == 1) && (pressed == 0))
765 BTIF_TRACE_DEBUG("%s: AVRC %s Release Faked earlier, drowned now",
766 __FUNCTION__, key_map[i].name);
769 send_key(uinput_fd, key_map[i].mapped_id, pressed);
770 if ((key_map[i].release_quirk == 1) && (pressed == 1))
773 BTIF_TRACE_DEBUG("%s: AVRC %s Release quirk enabled, send release now",
774 __FUNCTION__, key_map[i].name);
775 send_key(uinput_fd, key_map[i].mapped_id, 0);
781 if (key_map[i].name == NULL)
782 BTIF_TRACE_ERROR("%s AVRCP: unknown button 0x%02X %s", __FUNCTION__,
783 p_remote_cmd->rc_id, status);
786 /***************************************************************************
787 * Function handle_rc_passthrough_rsp
789 * - Argument: tBTA_AV_REMOTE_RSP passthrough command response
791 * - Description: Remote control passthrough response handler
793 ***************************************************************************/
794 void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
796 #if (AVRC_CTLR_INCLUDED == TRUE)
798 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
801 if (p_remote_rsp->key_state == AVRC_STATE_RELEASE)
812 BTIF_TRACE_DEBUG("%s: rc_id=%d status=%s", __FUNCTION__, p_remote_rsp->rc_id, status);
814 release_transaction(p_remote_rsp->label);
815 if (bt_rc_ctrl_callbacks != NULL) {
816 HAL_CBACK(bt_rc_ctrl_callbacks, passthrough_rsp_cb, p_remote_rsp->rc_id, key_state);
821 BTIF_TRACE_ERROR("%s DUT does not support AVRCP controller role", __FUNCTION__);
824 BTIF_TRACE_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
828 /***************************************************************************
829 * Function handle_rc_vendorunique_rsp
831 * - Argument: tBTA_AV_REMOTE_RSP command response
833 * - Description: Remote control vendor unique response handler
835 ***************************************************************************/
836 void handle_rc_vendorunique_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp)
838 #if (AVRC_CTLR_INCLUDED == TRUE)
841 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
844 if (p_remote_rsp->key_state == AVRC_STATE_RELEASE)
855 if (p_remote_rsp->len > 0)
857 if (p_remote_rsp->len >= AVRC_PASS_THRU_GROUP_LEN)
858 vendor_id = p_remote_rsp->p_data[AVRC_PASS_THRU_GROUP_LEN -1];
859 osi_free_and_reset((void **)&p_remote_rsp->p_data);
861 BTIF_TRACE_DEBUG("%s: vendor_id=%d status=%s", __FUNCTION__, vendor_id, status);
863 release_transaction(p_remote_rsp->label);
864 HAL_CBACK(bt_rc_ctrl_callbacks, groupnavigation_rsp_cb, vendor_id, key_state);
868 BTIF_TRACE_ERROR("%s Remote does not support AVRCP TG role", __FUNCTION__);
871 BTIF_TRACE_ERROR("%s AVRCP controller role is not enabled", __FUNCTION__);
875 void handle_uid_changed_notification(tBTA_AV_META_MSG *pmeta_msg, tAVRC_COMMAND *pavrc_command)
877 tAVRC_RESPONSE avrc_rsp = {0};
878 avrc_rsp.rsp.pdu = pavrc_command->pdu;
879 avrc_rsp.rsp.status = AVRC_STS_NO_ERROR;
880 avrc_rsp.rsp.opcode = pavrc_command->cmd.opcode;
882 avrc_rsp.reg_notif.event_id = pavrc_command->reg_notif.event_id;
883 avrc_rsp.reg_notif.param.uid_counter = 0;
885 send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_INTERIM, &avrc_rsp);
886 send_metamsg_rsp(pmeta_msg->rc_handle, pmeta_msg->label, AVRC_RSP_CHANGED, &avrc_rsp);
890 /***************************************************************************
891 * Function handle_rc_metamsg_cmd
893 * - Argument: tBTA_AV_VENDOR Structure containing the received
896 * - Description: Remote control metamsg command handler (AVRCP 1.3)
898 ***************************************************************************/
899 void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg)
901 /* Parse the metamsg command and pass it on to BTL-IFS */
902 UINT8 scratch_buf[512] = {0};
903 tAVRC_COMMAND avrc_command = {0};
906 BTIF_TRACE_EVENT("+ %s", __FUNCTION__);
908 if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR)
910 BTIF_TRACE_WARNING("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode);
913 if (pmeta_msg->len < 3)
915 BTIF_TRACE_WARNING("Invalid length.Opcode: 0x%x, len: 0x%x", pmeta_msg->p_msg->hdr.opcode,
920 if (pmeta_msg->code >= AVRC_RSP_NOT_IMPL)
922 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
924 rc_transaction_t *transaction=NULL;
925 transaction=get_transaction_by_lbl(pmeta_msg->label);
926 if (NULL!=transaction)
928 handle_rc_metamsg_rsp(pmeta_msg);
932 BTIF_TRACE_DEBUG("%s:Discard vendor dependent rsp. code: %d label:%d.",
933 __FUNCTION__, pmeta_msg->code, pmeta_msg->label);
939 BTIF_TRACE_DEBUG("%s:Received vendor dependent rsp. code: %d len: %d. Not processing it.",
940 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
946 status=AVRC_ParsCommand(pmeta_msg->p_msg, &avrc_command, scratch_buf, sizeof(scratch_buf));
947 BTIF_TRACE_DEBUG("%s Received vendor command.code,PDU and label: %d, %d,%d",
948 __FUNCTION__, pmeta_msg->code, avrc_command.cmd.pdu, pmeta_msg->label);
950 if (status != AVRC_STS_NO_ERROR)
953 BTIF_TRACE_WARNING("%s: Error in parsing received metamsg command. status: 0x%02x",
954 __FUNCTION__, status);
955 send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_command.pdu, status);
959 /* if RegisterNotification, add it to our registered queue */
961 if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION)
963 UINT8 event_id = avrc_command.reg_notif.event_id;
964 BTIF_TRACE_EVENT("%s:New register notification received.event_id:%s,label:0x%x,code:%x",
965 __FUNCTION__,dump_rc_notification_event_id(event_id), pmeta_msg->label,pmeta_msg->code);
966 btif_rc_cb.rc_notif[event_id-1].bNotify = TRUE;
967 btif_rc_cb.rc_notif[event_id-1].label = pmeta_msg->label;
969 if (event_id == AVRC_EVT_UIDS_CHANGE)
971 handle_uid_changed_notification(pmeta_msg, &avrc_command);
977 BTIF_TRACE_EVENT("%s: Passing received metamsg command to app. pdu: %s",
978 __FUNCTION__, dump_rc_pdu(avrc_command.cmd.pdu));
980 /* Since handle_rc_metamsg_cmd() itself is called from
981 *btif context, no context switching is required. Invoke
982 * btif_rc_upstreams_evt directly from here. */
983 btif_rc_upstreams_evt((uint16_t)avrc_command.cmd.pdu, &avrc_command, pmeta_msg->code,
988 /***************************************************************************
990 ** Function btif_rc_handler
992 ** Description RC event handler
994 ***************************************************************************/
995 void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
997 BTIF_TRACE_DEBUG ("%s event:%s", __FUNCTION__, dump_rc_event(event));
1000 case BTA_AV_RC_OPEN_EVT:
1002 BTIF_TRACE_DEBUG("%s Peer_features:%x", __FUNCTION__, p_data->rc_open.peer_features);
1003 handle_rc_connect( &(p_data->rc_open) );
1006 case BTA_AV_RC_CLOSE_EVT:
1008 handle_rc_disconnect( &(p_data->rc_close) );
1011 case BTA_AV_REMOTE_CMD_EVT:
1013 if (bt_rc_callbacks != NULL)
1015 BTIF_TRACE_DEBUG("%s rc_id:0x%x key_state:%d",
1016 __FUNCTION__, p_data->remote_cmd.rc_id,
1017 p_data->remote_cmd.key_state);
1018 /** In race conditions just after 2nd AVRCP is connected
1019 * remote might send pass through commands, so check for
1020 * Rc handle before processing pass through commands
1022 if (btif_rc_cb.rc_handle == p_data->remote_cmd.rc_handle)
1024 handle_rc_passthrough_cmd( (&p_data->remote_cmd) );
1028 BTIF_TRACE_DEBUG("%s Pass-through command for Invalid rc handle", __FUNCTION__);
1033 BTIF_TRACE_ERROR("AVRCP TG role not up, drop passthrough commands");
1038 #if (AVRC_CTLR_INCLUDED == TRUE)
1039 case BTA_AV_REMOTE_RSP_EVT:
1041 BTIF_TRACE_DEBUG("%s RSP: rc_id:0x%x key_state:%d",
1042 __FUNCTION__, p_data->remote_rsp.rc_id, p_data->remote_rsp.key_state);
1043 if (p_data->remote_rsp.rc_id == AVRC_ID_VENDOR)
1045 handle_rc_vendorunique_rsp(&p_data->remote_rsp);
1049 handle_rc_passthrough_rsp(&p_data->remote_rsp);
1055 case BTA_AV_RC_FEAT_EVT:
1057 BTIF_TRACE_DEBUG("%s Peer_features:%x", __FUNCTION__, p_data->rc_feat.peer_features);
1058 btif_rc_cb.rc_features = p_data->rc_feat.peer_features;
1059 handle_rc_features(p_data->rc_feat.peer_addr);
1060 #if (AVRC_CTLR_INCLUDED == TRUE)
1061 if ((btif_rc_cb.rc_connected) && (bt_rc_ctrl_callbacks != NULL))
1063 handle_rc_ctrl_features(btif_rc_cb.rc_addr);
1069 case BTA_AV_META_MSG_EVT:
1071 if (bt_rc_callbacks != NULL)
1073 BTIF_TRACE_DEBUG("%s BTA_AV_META_MSG_EVT code:%d label:%d",
1075 p_data->meta_msg.code,
1076 p_data->meta_msg.label);
1077 BTIF_TRACE_DEBUG("%s company_id:0x%x len:%d handle:%d",
1079 p_data->meta_msg.company_id,
1080 p_data->meta_msg.len,
1081 p_data->meta_msg.rc_handle);
1082 /* handle the metamsg command */
1083 handle_rc_metamsg_cmd(&(p_data->meta_msg));
1084 /* Free the Memory allocated for tAVRC_MSG */
1086 #if (AVRC_CTLR_INCLUDED == TRUE)
1087 else if ((bt_rc_callbacks == NULL)&&(bt_rc_ctrl_callbacks != NULL))
1089 /* This is case of Sink + CT + TG(for abs vol)) */
1090 BTIF_TRACE_DEBUG("%s BTA_AV_META_MSG_EVT code:%d label:%d",
1092 p_data->meta_msg.code,
1093 p_data->meta_msg.label);
1094 BTIF_TRACE_DEBUG("%s company_id:0x%x len:%d handle:%d",
1096 p_data->meta_msg.company_id,
1097 p_data->meta_msg.len,
1098 p_data->meta_msg.rc_handle);
1099 if ((p_data->meta_msg.code >= AVRC_RSP_NOT_IMPL)&&
1100 (p_data->meta_msg.code <= AVRC_RSP_INTERIM))
1102 /* Its a response */
1103 handle_avk_rc_metamsg_rsp(&(p_data->meta_msg));
1105 else if (p_data->meta_msg.code <= AVRC_CMD_GEN_INQ)
1108 handle_avk_rc_metamsg_cmd(&(p_data->meta_msg));
1115 BTIF_TRACE_ERROR("Neither CTRL, nor TG is up, drop meta commands");
1121 BTIF_TRACE_DEBUG("%s Unhandled RC event : 0x%x", __FUNCTION__, event);
1125 /***************************************************************************
1127 ** Function btif_rc_get_connected_peer
1129 ** Description Fetches the connected headset's BD_ADDR if any
1131 ***************************************************************************/
1132 BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr)
1134 if (btif_rc_cb.rc_connected == TRUE) {
1135 bdcpy(peer_addr, btif_rc_cb.rc_addr);
1141 /***************************************************************************
1143 ** Function btif_rc_get_connected_peer_handle
1145 ** Description Fetches the connected headset's handle if any
1147 ***************************************************************************/
1148 UINT8 btif_rc_get_connected_peer_handle(void)
1150 return btif_rc_cb.rc_handle;
1153 /***************************************************************************
1155 ** Function btif_rc_check_handle_pending_play
1157 ** Description Clears the queued PLAY command. if bSend is TRUE, forwards to app
1159 ***************************************************************************/
1161 /* clear the queued PLAY command. if bSend is TRUE, forward to app */
1162 void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp)
1166 BTIF_TRACE_DEBUG("%s: bSendToApp=%d", __FUNCTION__, bSendToApp);
1167 if (btif_rc_cb.rc_pending_play)
1171 tBTA_AV_REMOTE_CMD remote_cmd;
1172 APPL_TRACE_DEBUG("%s: Sending queued PLAYED event to app", __FUNCTION__);
1174 memset (&remote_cmd, 0, sizeof(tBTA_AV_REMOTE_CMD));
1175 remote_cmd.rc_handle = btif_rc_cb.rc_handle;
1176 remote_cmd.rc_id = AVRC_ID_PLAY;
1177 remote_cmd.hdr.ctype = AVRC_CMD_CTRL;
1178 remote_cmd.hdr.opcode = AVRC_OP_PASS_THRU;
1180 /* delay sending to app, else there is a timing issue in the framework,
1181 ** which causes the audio to be on th device's speaker. Delay between
1185 /* send to app - both PRESSED & RELEASED */
1186 remote_cmd.key_state = AVRC_STATE_PRESS;
1187 handle_rc_passthrough_cmd( &remote_cmd );
1191 remote_cmd.key_state = AVRC_STATE_RELEASE;
1192 handle_rc_passthrough_cmd( &remote_cmd );
1194 btif_rc_cb.rc_pending_play = FALSE;
1198 /* Generic reject response */
1199 static void send_reject_response (UINT8 rc_handle, UINT8 label, UINT8 pdu, UINT8 status)
1201 UINT8 ctype = AVRC_RSP_REJ;
1202 tAVRC_RESPONSE avrc_rsp;
1203 BT_HDR *p_msg = NULL;
1204 memset (&avrc_rsp, 0, sizeof(tAVRC_RESPONSE));
1206 avrc_rsp.rsp.opcode = opcode_from_pdu(pdu);
1207 avrc_rsp.rsp.pdu = pdu;
1208 avrc_rsp.rsp.status = status;
1210 if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(rc_handle, &avrc_rsp, &p_msg)) )
1212 BTIF_TRACE_DEBUG("%s:Sending error notification to handle:%d. pdu:%s,status:0x%02x",
1213 __FUNCTION__, rc_handle, dump_rc_pdu(pdu), status);
1214 BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
1218 /***************************************************************************
1219 * Function send_metamsg_rsp
1222 * rc_handle RC handle corresponding to the connected RC
1223 * label Label of the RC response
1224 * code Response type
1225 * pmetamsg_resp Vendor response
1227 * - Description: Remote control metamsg response handler (AVRCP 1.3)
1229 ***************************************************************************/
1230 static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label, tBTA_AV_CODE code,
1231 tAVRC_RESPONSE *pmetamsg_resp)
1237 BTIF_TRACE_WARNING("%s: Invalid response received from application", __FUNCTION__);
1241 BTIF_TRACE_EVENT("+%s: rc_handle: %d, label: %d, code: 0x%02x, pdu: %s", __FUNCTION__,
1242 rc_handle, label, code, dump_rc_pdu(pmetamsg_resp->rsp.pdu));
1244 if (pmetamsg_resp->rsp.status != AVRC_STS_NO_ERROR)
1246 ctype = AVRC_RSP_REJ;
1250 if ( code < AVRC_RSP_NOT_IMPL)
1252 if (code == AVRC_CMD_NOTIF)
1254 ctype = AVRC_RSP_INTERIM;
1256 else if (code == AVRC_CMD_STATUS)
1258 ctype = AVRC_RSP_IMPL_STBL;
1262 ctype = AVRC_RSP_ACCEPT;
1270 /* if response is for register_notification, make sure the rc has
1271 actually registered for this */
1272 if ((pmetamsg_resp->rsp.pdu == AVRC_PDU_REGISTER_NOTIFICATION) && (code == AVRC_RSP_CHANGED))
1274 BOOLEAN bSent = FALSE;
1275 UINT8 event_id = pmetamsg_resp->reg_notif.event_id;
1276 BOOLEAN bNotify = (btif_rc_cb.rc_connected) && (btif_rc_cb.rc_notif[event_id-1].bNotify);
1278 /* de-register this notification for a CHANGED response */
1279 btif_rc_cb.rc_notif[event_id-1].bNotify = FALSE;
1280 BTIF_TRACE_DEBUG("%s rc_handle: %d. event_id: 0x%02d bNotify:%u", __FUNCTION__,
1281 btif_rc_cb.rc_handle, event_id, bNotify);
1284 BT_HDR *p_msg = NULL;
1287 if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(btif_rc_cb.rc_handle,
1288 pmetamsg_resp, &p_msg)) )
1290 BTIF_TRACE_DEBUG("%s Sending notification to rc_handle: %d. event_id: 0x%02d",
1291 __FUNCTION__, btif_rc_cb.rc_handle, event_id);
1293 BTA_AvMetaRsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
1298 BTIF_TRACE_WARNING("%s failed to build metamsg response. status: 0x%02x",
1299 __FUNCTION__, status);
1306 BTIF_TRACE_DEBUG("%s: Notification not sent, as there are no RC connections or the \
1307 CT has not subscribed for event_id: %s", __FUNCTION__, dump_rc_notification_event_id(event_id));
1312 /* All other commands go here */
1314 BT_HDR *p_msg = NULL;
1317 status = AVRC_BldResponse(rc_handle, pmetamsg_resp, &p_msg);
1319 if (status == AVRC_STS_NO_ERROR)
1321 BTA_AvMetaRsp(rc_handle, label, ctype, p_msg);
1325 BTIF_TRACE_ERROR("%s: failed to build metamsg response. status: 0x%02x",
1326 __FUNCTION__, status);
1331 static UINT8 opcode_from_pdu(UINT8 pdu)
1337 case AVRC_PDU_NEXT_GROUP:
1338 case AVRC_PDU_PREV_GROUP: /* pass thru */
1339 opcode = AVRC_OP_PASS_THRU;
1342 default: /* vendor */
1343 opcode = AVRC_OP_VENDOR;
1350 /*******************************************************************************
1352 ** Function btif_rc_upstreams_evt
1354 ** Description Executes AVRC UPSTREAMS events in btif context.
1358 *******************************************************************************/
1359 static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND *pavrc_cmd, UINT8 ctype, UINT8 label)
1361 BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
1362 dump_rc_pdu(pavrc_cmd->pdu), btif_rc_cb.rc_handle, ctype, label);
1366 case AVRC_PDU_GET_PLAY_STATUS:
1368 FILL_PDU_QUEUE(IDX_GET_PLAY_STATUS_RSP, ctype, label, TRUE)
1369 HAL_CBACK(bt_rc_callbacks, get_play_status_cb);
1372 case AVRC_PDU_LIST_PLAYER_APP_ATTR:
1373 case AVRC_PDU_LIST_PLAYER_APP_VALUES:
1374 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
1375 case AVRC_PDU_SET_PLAYER_APP_VALUE:
1376 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
1377 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
1379 /* TODO: Add support for Application Settings */
1380 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_CMD);
1383 case AVRC_PDU_GET_ELEMENT_ATTR:
1385 btrc_media_attr_t element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
1387 memset(&element_attrs, 0, sizeof(element_attrs));
1388 if (pavrc_cmd->get_elem_attrs.num_attr == 0)
1390 /* CT requests for all attributes */
1392 num_attr = BTRC_MAX_ELEM_ATTR_SIZE;
1393 for (attr_cnt = 0; attr_cnt < BTRC_MAX_ELEM_ATTR_SIZE; attr_cnt++)
1395 element_attrs[attr_cnt] = attr_cnt + 1;
1398 else if (pavrc_cmd->get_elem_attrs.num_attr == 0xFF)
1400 /* 0xff indicates, no attributes requested - reject */
1401 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
1402 AVRC_STS_BAD_PARAM);
1407 int attr_cnt, filled_attr_count;
1410 /* Attribute IDs from 1 to AVRC_MAX_NUM_MEDIA_ATTR_ID are only valid,
1411 * hence HAL definition limits the attributes to AVRC_MAX_NUM_MEDIA_ATTR_ID.
1412 * Fill only valid entries.
1414 for (attr_cnt = 0; (attr_cnt < pavrc_cmd->get_elem_attrs.num_attr) &&
1415 (num_attr < AVRC_MAX_NUM_MEDIA_ATTR_ID); attr_cnt++)
1417 if ((pavrc_cmd->get_elem_attrs.attrs[attr_cnt] > 0) &&
1418 (pavrc_cmd->get_elem_attrs.attrs[attr_cnt] <= AVRC_MAX_NUM_MEDIA_ATTR_ID))
1420 /* Skip the duplicate entries : PTS sends duplicate entries for Fragment cases
1422 for (filled_attr_count = 0; filled_attr_count < num_attr; filled_attr_count++)
1424 if (element_attrs[filled_attr_count] == pavrc_cmd->get_elem_attrs.attrs[attr_cnt])
1427 if (filled_attr_count == num_attr)
1429 element_attrs[num_attr] = pavrc_cmd->get_elem_attrs.attrs[attr_cnt];
1435 FILL_PDU_QUEUE(IDX_GET_ELEMENT_ATTR_RSP, ctype, label, TRUE);
1436 HAL_CBACK(bt_rc_callbacks, get_element_attr_cb, num_attr, element_attrs);
1439 case AVRC_PDU_REGISTER_NOTIFICATION:
1441 if (pavrc_cmd->reg_notif.event_id == BTRC_EVT_PLAY_POS_CHANGED &&
1442 pavrc_cmd->reg_notif.param == 0)
1444 BTIF_TRACE_WARNING("%s Device registering position changed with illegal param 0.",
1446 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu, AVRC_STS_BAD_PARAM);
1447 /* de-register this notification for a rejected response */
1448 btif_rc_cb.rc_notif[BTRC_EVT_PLAY_POS_CHANGED - 1].bNotify = FALSE;
1451 HAL_CBACK(bt_rc_callbacks, register_notification_cb, pavrc_cmd->reg_notif.event_id,
1452 pavrc_cmd->reg_notif.param);
1455 case AVRC_PDU_INFORM_DISPLAY_CHARSET:
1457 tAVRC_RESPONSE avrc_rsp;
1458 BTIF_TRACE_EVENT("%s() AVRC_PDU_INFORM_DISPLAY_CHARSET", __FUNCTION__);
1459 if (btif_rc_cb.rc_connected == TRUE)
1461 memset(&(avrc_rsp.inform_charset), 0, sizeof(tAVRC_RSP));
1462 avrc_rsp.inform_charset.opcode=opcode_from_pdu(AVRC_PDU_INFORM_DISPLAY_CHARSET);
1463 avrc_rsp.inform_charset.pdu=AVRC_PDU_INFORM_DISPLAY_CHARSET;
1464 avrc_rsp.inform_charset.status=AVRC_STS_NO_ERROR;
1465 send_metamsg_rsp(btif_rc_cb.rc_handle, label, ctype, &avrc_rsp);
1471 send_reject_response (btif_rc_cb.rc_handle, label, pavrc_cmd->pdu,
1472 (pavrc_cmd->pdu == AVRC_PDU_SEARCH)?AVRC_STS_SEARCH_NOT_SUP:AVRC_STS_BAD_CMD);
1479 #if (AVRC_CTLR_INCLUDED == TRUE)
1480 /*******************************************************************************
1482 ** Function btif_rc_ctrl_upstreams_rsp_cmd
1484 ** Description Executes AVRC UPSTREAMS response events in btif context.
1488 *******************************************************************************/
1489 static void btif_rc_ctrl_upstreams_rsp_cmd(UINT8 event, tAVRC_COMMAND *pavrc_cmd,
1492 BTIF_TRACE_DEBUG("%s pdu: %s handle: 0x%x", __FUNCTION__,
1493 dump_rc_pdu(pavrc_cmd->pdu), btif_rc_cb.rc_handle);
1494 bt_bdaddr_t rc_addr;
1495 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
1496 #if (AVRC_CTLR_INCLUDED == TRUE)
1499 case AVRC_PDU_SET_ABSOLUTE_VOLUME:
1500 HAL_CBACK(bt_rc_ctrl_callbacks,setabsvol_cmd_cb, &rc_addr,
1501 pavrc_cmd->volume.volume, label);
1503 case AVRC_PDU_REGISTER_NOTIFICATION:
1504 if (pavrc_cmd->reg_notif.event_id == AVRC_EVT_VOLUME_CHANGE)
1506 HAL_CBACK(bt_rc_ctrl_callbacks, registernotification_absvol_cb,
1515 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
1516 /*******************************************************************************
1518 ** Function btif_rc_upstreams_rsp_evt
1520 ** Description Executes AVRC UPSTREAMS response events in btif context.
1524 *******************************************************************************/
1525 static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label)
1527 BTIF_TRACE_EVENT("%s pdu: %s handle: 0x%x ctype:%x label:%x", __FUNCTION__,
1528 dump_rc_pdu(pavrc_resp->pdu), btif_rc_cb.rc_handle, ctype, label);
1532 case AVRC_PDU_REGISTER_NOTIFICATION:
1534 if (AVRC_RSP_CHANGED==ctype)
1535 btif_rc_cb.rc_volume=pavrc_resp->reg_notif.param.volume;
1536 HAL_CBACK(bt_rc_callbacks, volume_change_cb, pavrc_resp->reg_notif.param.volume,ctype)
1540 case AVRC_PDU_SET_ABSOLUTE_VOLUME:
1542 BTIF_TRACE_DEBUG("%s Set absolute volume change event received: volume %d,ctype %d",
1543 __FUNCTION__, pavrc_resp->volume.volume,ctype);
1544 if (AVRC_RSP_ACCEPT==ctype)
1545 btif_rc_cb.rc_volume=pavrc_resp->volume.volume;
1546 HAL_CBACK(bt_rc_callbacks,volume_change_cb,pavrc_resp->volume.volume,ctype)
1556 /************************************************************************************
1557 ** AVRCP API Functions
1558 ************************************************************************************/
1560 /*******************************************************************************
1564 ** Description Initializes the AVRC interface
1566 ** Returns bt_status_t
1568 *******************************************************************************/
1569 static bt_status_t init(btrc_callbacks_t* callbacks )
1571 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
1572 bt_status_t result = BT_STATUS_SUCCESS;
1574 if (bt_rc_callbacks)
1575 return BT_STATUS_DONE;
1577 bt_rc_callbacks = callbacks;
1578 memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
1579 btif_rc_cb.rc_vol_label=MAX_LABEL;
1580 btif_rc_cb.rc_volume=MAX_VOLUME;
1586 /*******************************************************************************
1588 ** Function init_ctrl
1590 ** Description Initializes the AVRC interface
1592 ** Returns bt_status_t
1594 *******************************************************************************/
1595 static bt_status_t init_ctrl(btrc_ctrl_callbacks_t* callbacks )
1597 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
1598 bt_status_t result = BT_STATUS_SUCCESS;
1600 if (bt_rc_ctrl_callbacks)
1601 return BT_STATUS_DONE;
1603 bt_rc_ctrl_callbacks = callbacks;
1604 memset (&btif_rc_cb, 0, sizeof(btif_rc_cb));
1605 btif_rc_cb.rc_vol_label=MAX_LABEL;
1606 btif_rc_cb.rc_volume=MAX_VOLUME;
1612 static void rc_ctrl_procedure_complete ()
1614 if (btif_rc_cb.rc_procedure_complete == TRUE)
1618 btif_rc_cb.rc_procedure_complete = TRUE;
1619 UINT32 attr_list[] = {
1620 AVRC_MEDIA_ATTR_ID_TITLE,
1621 AVRC_MEDIA_ATTR_ID_ARTIST,
1622 AVRC_MEDIA_ATTR_ID_ALBUM,
1623 AVRC_MEDIA_ATTR_ID_TRACK_NUM,
1624 AVRC_MEDIA_ATTR_ID_NUM_TRACKS,
1625 AVRC_MEDIA_ATTR_ID_GENRE,
1626 AVRC_MEDIA_ATTR_ID_PLAYING_TIME
1628 get_element_attribute_cmd (AVRC_MAX_NUM_MEDIA_ATTR_ID, attr_list);
1631 /***************************************************************************
1633 ** Function get_play_status_rsp
1635 ** Description Returns the current play status.
1636 ** This method is called in response to
1637 ** GetPlayStatus request.
1639 ** Returns bt_status_t
1641 ***************************************************************************/
1642 static bt_status_t get_play_status_rsp(btrc_play_status_t play_status, uint32_t song_len,
1645 tAVRC_RESPONSE avrc_rsp;
1647 memset(&(avrc_rsp.get_play_status), 0, sizeof(tAVRC_GET_PLAY_STATUS_RSP));
1648 avrc_rsp.get_play_status.song_len = song_len;
1649 avrc_rsp.get_play_status.song_pos = song_pos;
1650 avrc_rsp.get_play_status.play_status = play_status;
1652 avrc_rsp.get_play_status.pdu = AVRC_PDU_GET_PLAY_STATUS;
1653 avrc_rsp.get_play_status.opcode = opcode_from_pdu(AVRC_PDU_GET_PLAY_STATUS);
1654 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1655 /* Send the response */
1656 SEND_METAMSG_RSP(IDX_GET_PLAY_STATUS_RSP, &avrc_rsp);
1657 return BT_STATUS_SUCCESS;
1660 /***************************************************************************
1662 ** Function get_element_attr_rsp
1664 ** Description Returns the current songs' element attributes
1667 ** Returns bt_status_t
1669 ***************************************************************************/
1670 static bt_status_t get_element_attr_rsp(uint8_t num_attr, btrc_element_attr_val_t *p_attrs)
1672 tAVRC_RESPONSE avrc_rsp;
1674 tAVRC_ATTR_ENTRY element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
1676 memset(element_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr);
1680 avrc_rsp.get_play_status.status = AVRC_STS_BAD_PARAM;
1684 for (i=0; i<num_attr; i++) {
1685 element_attrs[i].attr_id = p_attrs[i].attr_id;
1686 element_attrs[i].name.charset_id = AVRC_CHARSET_ID_UTF8;
1687 element_attrs[i].name.str_len = (UINT16)strlen((char *)p_attrs[i].text);
1688 element_attrs[i].name.p_str = p_attrs[i].text;
1689 BTIF_TRACE_DEBUG("%s attr_id:0x%x, charset_id:0x%x, str_len:%d, str:%s",
1690 __FUNCTION__, (unsigned int)element_attrs[i].attr_id,
1691 element_attrs[i].name.charset_id, element_attrs[i].name.str_len,
1692 element_attrs[i].name.p_str);
1694 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1696 avrc_rsp.get_elem_attrs.num_attr = num_attr;
1697 avrc_rsp.get_elem_attrs.p_attrs = element_attrs;
1698 avrc_rsp.get_elem_attrs.pdu = AVRC_PDU_GET_ELEMENT_ATTR;
1699 avrc_rsp.get_elem_attrs.opcode = opcode_from_pdu(AVRC_PDU_GET_ELEMENT_ATTR);
1700 /* Send the response */
1701 SEND_METAMSG_RSP(IDX_GET_ELEMENT_ATTR_RSP, &avrc_rsp);
1702 return BT_STATUS_SUCCESS;
1705 /***************************************************************************
1707 ** Function register_notification_rsp
1709 ** Description Response to the register notification request.
1712 ** Returns bt_status_t
1714 ***************************************************************************/
1715 static bt_status_t register_notification_rsp(btrc_event_id_t event_id,
1716 btrc_notification_type_t type, btrc_register_notification_t *p_param)
1718 tAVRC_RESPONSE avrc_rsp;
1720 BTIF_TRACE_EVENT("## %s ## event_id:%s", __FUNCTION__, dump_rc_notification_event_id(event_id));
1721 if (btif_rc_cb.rc_notif[event_id-1].bNotify == FALSE)
1723 BTIF_TRACE_ERROR("Avrcp Event id not registered: event_id = %x", event_id);
1724 return BT_STATUS_NOT_READY;
1726 memset(&(avrc_rsp.reg_notif), 0, sizeof(tAVRC_REG_NOTIF_RSP));
1727 avrc_rsp.reg_notif.event_id = event_id;
1731 case BTRC_EVT_PLAY_STATUS_CHANGED:
1732 avrc_rsp.reg_notif.param.play_status = p_param->play_status;
1733 if (avrc_rsp.reg_notif.param.play_status == PLAY_STATUS_PLAYING)
1734 btif_av_clear_remote_suspend_flag();
1736 case BTRC_EVT_TRACK_CHANGE:
1737 memcpy(&(avrc_rsp.reg_notif.param.track), &(p_param->track), sizeof(btrc_uid_t));
1739 case BTRC_EVT_PLAY_POS_CHANGED:
1740 avrc_rsp.reg_notif.param.play_pos = p_param->song_pos;
1743 BTIF_TRACE_WARNING("%s : Unhandled event ID : 0x%x", __FUNCTION__, event_id);
1744 return BT_STATUS_UNHANDLED;
1747 avrc_rsp.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
1748 avrc_rsp.reg_notif.opcode = opcode_from_pdu(AVRC_PDU_REGISTER_NOTIFICATION);
1749 avrc_rsp.get_play_status.status = AVRC_STS_NO_ERROR;
1751 /* Send the response. */
1752 send_metamsg_rsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label,
1753 ((type == BTRC_NOTIFICATION_TYPE_INTERIM)?AVRC_CMD_NOTIF:AVRC_RSP_CHANGED), &avrc_rsp);
1754 return BT_STATUS_SUCCESS;
1757 /***************************************************************************
1759 ** Function set_volume
1761 ** Description Send current volume setting to remote side.
1762 ** Support limited to SetAbsoluteVolume
1763 ** This can be enhanced to support Relative Volume (AVRCP 1.0).
1764 ** With RelateVolume, we will send VOLUME_UP/VOLUME_DOWN
1765 ** as opposed to absolute volume level
1766 ** volume: Should be in the range 0-127. bit7 is reseved and cannot be set
1768 ** Returns bt_status_t
1770 ***************************************************************************/
1771 static bt_status_t set_volume(uint8_t volume)
1773 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
1775 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
1776 rc_transaction_t *p_transaction=NULL;
1778 if (btif_rc_cb.rc_volume==volume)
1780 status=BT_STATUS_DONE;
1781 BTIF_TRACE_ERROR("%s: volume value already set earlier: 0x%02x",__FUNCTION__, volume);
1785 if ((btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG) &&
1786 (btif_rc_cb.rc_features & BTA_AV_FEAT_ADV_CTRL))
1788 tAVRC_COMMAND avrc_cmd = {0};
1789 BT_HDR *p_msg = NULL;
1791 BTIF_TRACE_DEBUG("%s: Peer supports absolute volume. newVolume=%d", __FUNCTION__, volume);
1792 avrc_cmd.volume.opcode = AVRC_OP_VENDOR;
1793 avrc_cmd.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME;
1794 avrc_cmd.volume.status = AVRC_STS_NO_ERROR;
1795 avrc_cmd.volume.volume = volume;
1797 if (AVRC_BldCommand(&avrc_cmd, &p_msg) == AVRC_STS_NO_ERROR)
1799 bt_status_t tran_status=get_transaction(&p_transaction);
1800 if (BT_STATUS_SUCCESS == tran_status && NULL!=p_transaction)
1802 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
1803 __FUNCTION__,p_transaction->lbl);
1804 BTA_AvMetaCmd(btif_rc_cb.rc_handle,p_transaction->lbl, AVRC_CMD_CTRL, p_msg);
1805 status = BT_STATUS_SUCCESS;
1810 BTIF_TRACE_ERROR("%s: failed to obtain transaction details. status: 0x%02x",
1811 __FUNCTION__, tran_status);
1812 status = BT_STATUS_FAIL;
1817 BTIF_TRACE_ERROR("%s: failed to build absolute volume command. status: 0x%02x",
1818 __FUNCTION__, status);
1819 status = BT_STATUS_FAIL;
1823 status=BT_STATUS_NOT_READY;
1827 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
1828 /***************************************************************************
1830 ** Function register_volumechange
1832 ** Description Register for volume change notification from remote side.
1836 ***************************************************************************/
1838 static void register_volumechange (UINT8 lbl)
1840 tAVRC_COMMAND avrc_cmd = {0};
1841 BT_HDR *p_msg = NULL;
1842 tAVRC_STS BldResp=AVRC_STS_BAD_CMD;
1843 rc_transaction_t *p_transaction=NULL;
1845 BTIF_TRACE_DEBUG("%s called with label:%d",__FUNCTION__,lbl);
1847 avrc_cmd.cmd.opcode=0x00;
1848 avrc_cmd.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
1849 avrc_cmd.reg_notif.event_id = AVRC_EVT_VOLUME_CHANGE;
1850 avrc_cmd.reg_notif.status = AVRC_STS_NO_ERROR;
1851 avrc_cmd.reg_notif.param = 0;
1853 BldResp=AVRC_BldCommand(&avrc_cmd, &p_msg);
1854 if (AVRC_STS_NO_ERROR == BldResp && p_msg) {
1855 p_transaction = get_transaction_by_lbl(lbl);
1856 if (p_transaction != NULL) {
1857 BTA_AvMetaCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
1858 AVRC_CMD_NOTIF, p_msg);
1859 BTIF_TRACE_DEBUG("%s:BTA_AvMetaCmd called", __func__);
1862 BTIF_TRACE_ERROR("%s transaction not obtained with label: %d",
1866 BTIF_TRACE_ERROR("%s failed to build command:%d", __func__, BldResp);
1870 /***************************************************************************
1872 ** Function handle_rc_metamsg_rsp
1874 ** Description Handle RC metamessage response
1878 ***************************************************************************/
1879 static void handle_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg)
1881 tAVRC_RESPONSE avrc_response = {0};
1882 UINT8 scratch_buf[512] = {0};
1883 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
1885 if (AVRC_OP_VENDOR==pmeta_msg->p_msg->hdr.opcode &&(AVRC_RSP_CHANGED==pmeta_msg->code
1886 || AVRC_RSP_INTERIM==pmeta_msg->code || AVRC_RSP_ACCEPT==pmeta_msg->code
1887 || AVRC_RSP_REJ==pmeta_msg->code || AVRC_RSP_NOT_IMPL==pmeta_msg->code))
1889 status=AVRC_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, sizeof(scratch_buf));
1890 BTIF_TRACE_DEBUG("%s: code %d,event ID %d,PDU %x,parsing status %d, label:%d",
1891 __FUNCTION__,pmeta_msg->code,avrc_response.reg_notif.event_id,avrc_response.reg_notif.pdu,
1892 status, pmeta_msg->label);
1894 if (status != AVRC_STS_NO_ERROR)
1896 if (AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1897 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1898 && btif_rc_cb.rc_vol_label==pmeta_msg->label)
1900 btif_rc_cb.rc_vol_label=MAX_LABEL;
1901 release_transaction(btif_rc_cb.rc_vol_label);
1903 else if (AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
1905 release_transaction(pmeta_msg->label);
1909 else if (AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1910 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1911 && btif_rc_cb.rc_vol_label!=pmeta_msg->label)
1913 // Just discard the message, if the device sends back with an incorrect label
1914 BTIF_TRACE_DEBUG("%s:Discarding register notfn in rsp.code: %d and label %d",
1915 __FUNCTION__, pmeta_msg->code, pmeta_msg->label);
1921 BTIF_TRACE_DEBUG("%s:Received vendor dependent in adv ctrl rsp. code: %d len: %d. Not processing it.",
1922 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
1926 if (AVRC_PDU_REGISTER_NOTIFICATION==avrc_response.rsp.pdu
1927 && AVRC_EVT_VOLUME_CHANGE==avrc_response.reg_notif.event_id
1928 && AVRC_RSP_CHANGED==pmeta_msg->code)
1930 /* re-register for volume change notification */
1931 // Do not re-register for rejected case, as it might get into endless loop
1932 register_volumechange(btif_rc_cb.rc_vol_label);
1934 else if (AVRC_PDU_SET_ABSOLUTE_VOLUME==avrc_response.rsp.pdu)
1936 /* free up the label here */
1937 release_transaction(pmeta_msg->label);
1940 BTIF_TRACE_EVENT("%s: Passing received metamsg response to app. pdu: %s",
1941 __FUNCTION__, dump_rc_pdu(avrc_response.pdu));
1942 btif_rc_upstreams_rsp_evt((uint16_t)avrc_response.rsp.pdu, &avrc_response, pmeta_msg->code,
1947 #if (AVRC_CTLR_INCLUDED == TRUE)
1948 /***************************************************************************
1950 ** Function iterate_supported_event_list_for_interim_rsp
1952 ** Description iterator callback function to match the event and handle
1954 ** Returns true to continue iterating, false to stop
1956 ***************************************************************************/
1957 bool iterate_supported_event_list_for_interim_rsp(void *data, void *cb_data)
1960 btif_rc_supported_event_t *p_event = (btif_rc_supported_event_t *)data;
1962 p_event_id = (UINT8*)cb_data;
1964 if (p_event->event_id == *p_event_id)
1966 p_event->status = eINTERIM;
1972 /***************************************************************************
1974 ** Function iterate_supported_event_list_for_timeout
1976 ** Description Iterator callback function for timeout handling.
1977 ** As part of the failure handling, it releases the
1978 ** transaction label and removes the event from list,
1979 ** this event will not be requested again during
1980 ** the lifetime of the connection.
1981 ** Returns false to stop iterating, true to continue
1983 ***************************************************************************/
1984 bool iterate_supported_event_list_for_timeout(void *data, void *cb_data)
1987 btif_rc_supported_event_t *p_event = (btif_rc_supported_event_t *)data;
1989 label = (*(UINT8*)cb_data) & 0xFF;
1991 if (p_event->label == label)
1993 list_remove(btif_rc_cb.rc_supported_event_list, p_event);
1999 /***************************************************************************
2001 ** Function rc_notification_interim_timout
2003 ** Description Interim response timeout handler.
2004 ** Runs the iterator to check and clear the timed out event.
2005 ** Proceeds to register for the unregistered events.
2008 ***************************************************************************/
2009 static void rc_notification_interim_timout (UINT8 label)
2013 list_foreach(btif_rc_cb.rc_supported_event_list,
2014 iterate_supported_event_list_for_timeout, &label);
2015 /* Timeout happened for interim response for the registered event,
2016 * check if there are any pending for registration
2018 node = list_begin(btif_rc_cb.rc_supported_event_list);
2019 while (node != NULL)
2021 btif_rc_supported_event_t *p_event;
2023 p_event = (btif_rc_supported_event_t *)list_node(node);
2024 if ((p_event != NULL) && (p_event->status == eNOT_REGISTERED))
2026 register_for_event_notification(p_event);
2029 node = list_next (node);
2031 /* Todo. Need to initiate application settings query if this
2032 * is the last event registration.
2036 /***************************************************************************
2038 ** Function btif_rc_status_cmd_timeout_handler
2040 ** Description RC status command timeout handler (Runs in BTIF context).
2043 ***************************************************************************/
2044 static void btif_rc_status_cmd_timeout_handler(UNUSED_ATTR uint16_t event,
2047 btif_rc_timer_context_t *p_context;
2048 tAVRC_RESPONSE avrc_response = {0};
2049 tBTA_AV_META_MSG meta_msg;
2051 p_context = (btif_rc_timer_context_t *)data;
2052 memset(&meta_msg, 0, sizeof(tBTA_AV_META_MSG));
2053 meta_msg.rc_handle = btif_rc_cb.rc_handle;
2055 switch (p_context->rc_status_cmd.pdu_id) {
2056 case AVRC_PDU_REGISTER_NOTIFICATION:
2057 rc_notification_interim_timout(p_context->rc_status_cmd.label);
2060 case AVRC_PDU_GET_CAPABILITIES:
2061 avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
2062 handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
2065 case AVRC_PDU_LIST_PLAYER_APP_ATTR:
2066 avrc_response.list_app_attr.status = BTIF_RC_STS_TIMEOUT;
2067 handle_app_attr_response(&meta_msg, &avrc_response.list_app_attr);
2070 case AVRC_PDU_LIST_PLAYER_APP_VALUES:
2071 avrc_response.list_app_values.status = BTIF_RC_STS_TIMEOUT;
2072 handle_app_val_response(&meta_msg, &avrc_response.list_app_values);
2075 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
2076 avrc_response.get_cur_app_val.status = BTIF_RC_STS_TIMEOUT;
2077 handle_app_cur_val_response(&meta_msg, &avrc_response.get_cur_app_val);
2080 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
2081 avrc_response.get_app_attr_txt.status = BTIF_RC_STS_TIMEOUT;
2082 handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_attr_txt);
2085 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
2086 avrc_response.get_app_val_txt.status = BTIF_RC_STS_TIMEOUT;
2087 handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_val_txt);
2090 case AVRC_PDU_GET_ELEMENT_ATTR:
2091 avrc_response.get_elem_attrs.status = BTIF_RC_STS_TIMEOUT;
2092 handle_get_elem_attr_response(&meta_msg, &avrc_response.get_elem_attrs);
2095 case AVRC_PDU_GET_PLAY_STATUS:
2096 avrc_response.get_play_status.status = BTIF_RC_STS_TIMEOUT;
2097 handle_get_playstatus_response(&meta_msg, &avrc_response.get_play_status);
2100 release_transaction(p_context->rc_status_cmd.label);
2103 /***************************************************************************
2105 ** Function btif_rc_status_cmd_timer_timeout
2107 ** Description RC status command timeout callback.
2108 ** This is called from BTU context and switches to BTIF
2109 ** context to handle the timeout events
2112 ***************************************************************************/
2113 static void btif_rc_status_cmd_timer_timeout(void *data)
2115 btif_rc_timer_context_t *p_data = (btif_rc_timer_context_t *)data;
2117 btif_transfer_context(btif_rc_status_cmd_timeout_handler, 0,
2118 (char *)p_data, sizeof(btif_rc_timer_context_t),
2122 /***************************************************************************
2124 ** Function btif_rc_control_cmd_timeout_handler
2126 ** Description RC control command timeout handler (Runs in BTIF context).
2129 ***************************************************************************/
2130 static void btif_rc_control_cmd_timeout_handler(UNUSED_ATTR uint16_t event,
2133 btif_rc_timer_context_t *p_context = (btif_rc_timer_context_t *)data;
2134 tAVRC_RESPONSE avrc_response = {0};
2135 tBTA_AV_META_MSG meta_msg;
2137 memset(&meta_msg, 0, sizeof(tBTA_AV_META_MSG));
2138 meta_msg.rc_handle = btif_rc_cb.rc_handle;
2140 switch (p_context->rc_control_cmd.pdu_id) {
2141 case AVRC_PDU_SET_PLAYER_APP_VALUE:
2142 avrc_response.set_app_val.status = BTIF_RC_STS_TIMEOUT;
2143 handle_set_app_attr_val_response(&meta_msg,
2144 &avrc_response.set_app_val);
2147 release_transaction(p_context->rc_control_cmd.label);
2150 /***************************************************************************
2152 ** Function btif_rc_control_cmd_timer_timeout
2154 ** Description RC control command timeout callback.
2155 ** This is called from BTU context and switches to BTIF
2156 ** context to handle the timeout events
2159 ***************************************************************************/
2160 static void btif_rc_control_cmd_timer_timeout(void *data)
2162 btif_rc_timer_context_t *p_data = (btif_rc_timer_context_t *)data;
2164 btif_transfer_context(btif_rc_control_cmd_timeout_handler, 0,
2165 (char *)p_data, sizeof(btif_rc_timer_context_t),
2169 /***************************************************************************
2171 ** Function btif_rc_play_status_timeout_handler
2173 ** Description RC play status timeout handler (Runs in BTIF context).
2176 ***************************************************************************/
2177 static void btif_rc_play_status_timeout_handler(UNUSED_ATTR uint16_t event,
2178 UNUSED_ATTR char *p_data)
2180 get_play_status_cmd();
2181 rc_start_play_status_timer();
2184 /***************************************************************************
2186 ** Function btif_rc_play_status_timer_timeout
2188 ** Description RC play status timeout callback.
2189 ** This is called from BTU context and switches to BTIF
2190 ** context to handle the timeout events
2193 ***************************************************************************/
2194 static void btif_rc_play_status_timer_timeout(UNUSED_ATTR void *data)
2196 btif_transfer_context(btif_rc_play_status_timeout_handler, 0, 0, 0, NULL);
2199 /***************************************************************************
2201 ** Function rc_start_play_status_timer
2203 ** Description Helper function to start the timer to fetch play status.
2206 ***************************************************************************/
2207 static void rc_start_play_status_timer(void)
2209 /* Start the Play status timer only if it is not started */
2210 if (!alarm_is_scheduled(btif_rc_cb.rc_play_status_timer)) {
2211 if (btif_rc_cb.rc_play_status_timer == NULL) {
2212 btif_rc_cb.rc_play_status_timer =
2213 alarm_new("btif_rc.rc_play_status_timer");
2215 alarm_set_on_queue(btif_rc_cb.rc_play_status_timer,
2216 BTIF_TIMEOUT_RC_INTERIM_RSP_MS,
2217 btif_rc_play_status_timer_timeout, NULL,
2218 btu_general_alarm_queue);
2222 /***************************************************************************
2224 ** Function rc_stop_play_status_timer
2226 ** Description Helper function to stop the play status timer.
2229 ***************************************************************************/
2230 void rc_stop_play_status_timer()
2232 if (btif_rc_cb.rc_play_status_timer != NULL)
2233 alarm_cancel(btif_rc_cb.rc_play_status_timer);
2236 /***************************************************************************
2238 ** Function register_for_event_notification
2240 ** Description Helper function registering notification events
2241 ** sets an interim response timeout to handle if the remote
2242 ** does not respond.
2245 ***************************************************************************/
2246 static void register_for_event_notification(btif_rc_supported_event_t *p_event)
2249 rc_transaction_t *p_transaction;
2251 status = get_transaction(&p_transaction);
2252 if (status == BT_STATUS_SUCCESS)
2254 btif_rc_timer_context_t *p_context = &p_transaction->txn_timer_context;
2256 status = register_notification_cmd (p_transaction->lbl, p_event->event_id, 0);
2257 if (status != BT_STATUS_SUCCESS)
2259 BTIF_TRACE_ERROR("%s Error in Notification registration %d",
2260 __FUNCTION__, status);
2261 release_transaction (p_transaction->lbl);
2264 p_event->label = p_transaction->lbl;
2265 p_event->status = eREGISTERED;
2266 p_context->rc_status_cmd.label = p_transaction->lbl;
2267 p_context->rc_status_cmd.pdu_id = AVRC_PDU_REGISTER_NOTIFICATION;
2269 alarm_free(p_transaction->txn_timer);
2270 p_transaction->txn_timer =
2271 alarm_new("btif_rc.status_command_txn_timer");
2272 alarm_set_on_queue(p_transaction->txn_timer,
2273 BTIF_TIMEOUT_RC_INTERIM_RSP_MS,
2274 btif_rc_status_cmd_timer_timeout, p_context,
2275 btu_general_alarm_queue);
2279 BTIF_TRACE_ERROR("%s Error No more Transaction label %d",
2280 __FUNCTION__, status);
2284 static void start_status_command_timer(UINT8 pdu_id, rc_transaction_t *p_txn)
2286 btif_rc_timer_context_t *p_context = &p_txn->txn_timer_context;
2287 p_context->rc_status_cmd.label = p_txn->lbl;
2288 p_context->rc_status_cmd.pdu_id = pdu_id;
2290 alarm_free(p_txn->txn_timer);
2291 p_txn->txn_timer = alarm_new("btif_rc.status_command_txn_timer");
2292 alarm_set_on_queue(p_txn->txn_timer, BTIF_TIMEOUT_RC_STATUS_CMD_MS,
2293 btif_rc_status_cmd_timer_timeout, p_context,
2294 btu_general_alarm_queue);
2297 static void start_control_command_timer(UINT8 pdu_id, rc_transaction_t *p_txn)
2299 btif_rc_timer_context_t *p_context = &p_txn->txn_timer_context;
2300 p_context->rc_control_cmd.label = p_txn->lbl;
2301 p_context->rc_control_cmd.pdu_id = pdu_id;
2303 alarm_free(p_txn->txn_timer);
2304 p_txn->txn_timer = alarm_new("btif_rc.control_command_txn_timer");
2305 alarm_set_on_queue(p_txn->txn_timer,
2306 BTIF_TIMEOUT_RC_CONTROL_CMD_MS,
2307 btif_rc_control_cmd_timer_timeout, p_context,
2308 btu_general_alarm_queue);
2311 /***************************************************************************
2313 ** Function handle_get_capability_response
2315 ** Description Handles the get_cap_response to populate company id info
2316 ** and query the supported events.
2317 ** Initiates Notification registration for events supported
2320 ***************************************************************************/
2321 static void handle_get_capability_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CAPS_RSP *p_rsp)
2325 /* Todo: Do we need to retry on command timeout */
2326 if (p_rsp->status != AVRC_STS_NO_ERROR)
2328 BTIF_TRACE_ERROR("%s Error capability response 0x%02X",
2329 __FUNCTION__, p_rsp->status);
2333 if (p_rsp->capability_id == AVRC_CAP_EVENTS_SUPPORTED)
2335 btif_rc_supported_event_t *p_event;
2337 /* Todo: Check if list can be active when we hit here */
2338 btif_rc_cb.rc_supported_event_list = list_new(osi_free);
2339 for (xx = 0; xx < p_rsp->count; xx++)
2341 /* Skip registering for Play position change notification */
2342 if ((p_rsp->param.event_id[xx] == AVRC_EVT_PLAY_STATUS_CHANGE)||
2343 (p_rsp->param.event_id[xx] == AVRC_EVT_TRACK_CHANGE)||
2344 (p_rsp->param.event_id[xx] == AVRC_EVT_APP_SETTING_CHANGE))
2346 p_event = (btif_rc_supported_event_t *)osi_malloc(sizeof(btif_rc_supported_event_t));
2347 p_event->event_id = p_rsp->param.event_id[xx];
2348 p_event->status = eNOT_REGISTERED;
2349 list_append(btif_rc_cb.rc_supported_event_list, p_event);
2352 p_event = list_front(btif_rc_cb.rc_supported_event_list);
2353 if (p_event != NULL)
2355 register_for_event_notification(p_event);
2358 else if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID)
2360 getcapabilities_cmd (AVRC_CAP_EVENTS_SUPPORTED);
2361 BTIF_TRACE_EVENT("%s AVRC_CAP_COMPANY_ID: ", __FUNCTION__);
2362 for (xx = 0; xx < p_rsp->count; xx++)
2364 BTIF_TRACE_EVENT("%s : %d", __FUNCTION__, p_rsp->param.company_id[xx]);
2369 bool rc_is_track_id_valid (tAVRC_UID uid)
2371 tAVRC_UID invalid_uid = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
2373 if (memcmp(uid, invalid_uid, sizeof(tAVRC_UID)) == 0)
2383 /***************************************************************************
2385 ** Function handle_notification_response
2387 ** Description Main handler for notification responses to registered events
2388 ** 1. Register for unregistered event(in interim response path)
2389 ** 2. After registering for all supported events, start
2390 ** retrieving application settings and values
2391 ** 3. Reregister for events on getting changed response
2392 ** 4. Run play status timer for getting position when the
2393 ** status changes to playing
2394 ** 5. Get the Media details when the track change happens
2395 ** or track change interim response is received with
2397 ** 6. HAL callback for play status change and application
2401 ***************************************************************************/
2402 static void handle_notification_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_REG_NOTIF_RSP *p_rsp)
2404 bt_bdaddr_t rc_addr;
2405 UINT32 attr_list[] = {
2406 AVRC_MEDIA_ATTR_ID_TITLE,
2407 AVRC_MEDIA_ATTR_ID_ARTIST,
2408 AVRC_MEDIA_ATTR_ID_ALBUM,
2409 AVRC_MEDIA_ATTR_ID_TRACK_NUM,
2410 AVRC_MEDIA_ATTR_ID_NUM_TRACKS,
2411 AVRC_MEDIA_ATTR_ID_GENRE,
2412 AVRC_MEDIA_ATTR_ID_PLAYING_TIME
2416 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2418 if (pmeta_msg->code == AVRC_RSP_INTERIM)
2420 btif_rc_supported_event_t *p_event;
2423 BTIF_TRACE_DEBUG("%s Interim response : 0x%2X ", __FUNCTION__, p_rsp->event_id);
2424 switch (p_rsp->event_id)
2426 case AVRC_EVT_PLAY_STATUS_CHANGE:
2427 /* Start timer to get play status periodically
2428 * if the play state is playing.
2430 if (p_rsp->param.play_status == AVRC_PLAYSTATE_PLAYING)
2432 rc_start_play_status_timer();
2434 HAL_CBACK(bt_rc_ctrl_callbacks, play_status_changed_cb,
2435 &rc_addr, p_rsp->param.play_status);
2438 case AVRC_EVT_TRACK_CHANGE:
2439 if (rc_is_track_id_valid (p_rsp->param.track) != true)
2445 UINT8 *p_data = p_rsp->param.track;
2446 /* Update the UID for current track
2447 * Attributes will be fetched after the AVRCP procedure
2449 BE_STREAM_TO_UINT64(btif_rc_cb.rc_playing_uid, p_data);
2453 case AVRC_EVT_APP_SETTING_CHANGE:
2456 case AVRC_EVT_NOW_PLAYING_CHANGE:
2459 case AVRC_EVT_AVAL_PLAYERS_CHANGE:
2462 case AVRC_EVT_ADDR_PLAYER_CHANGE:
2465 case AVRC_EVT_UIDS_CHANGE:
2468 case AVRC_EVT_TRACK_REACHED_END:
2469 case AVRC_EVT_TRACK_REACHED_START:
2470 case AVRC_EVT_PLAY_POS_CHANGED:
2471 case AVRC_EVT_BATTERY_STATUS_CHANGE:
2472 case AVRC_EVT_SYSTEM_STATUS_CHANGE:
2474 BTIF_TRACE_ERROR("%s Unhandled interim response 0x%2X", __FUNCTION__,
2478 list_foreach(btif_rc_cb.rc_supported_event_list,
2479 iterate_supported_event_list_for_interim_rsp,
2482 node = list_begin(btif_rc_cb.rc_supported_event_list);
2483 while (node != NULL)
2485 p_event = (btif_rc_supported_event_t *)list_node(node);
2486 if ((p_event != NULL) && (p_event->status == eNOT_REGISTERED))
2488 register_for_event_notification(p_event);
2491 node = list_next (node);
2494 /* Registered for all events, we can request application settings */
2495 if ((p_event == NULL) && (btif_rc_cb.rc_app_settings.query_started == false))
2497 /* we need to do this only if remote TG supports
2498 * player application settings
2500 btif_rc_cb.rc_app_settings.query_started = TRUE;
2501 if (btif_rc_cb.rc_features & BTA_AV_FEAT_APP_SETTING)
2503 list_player_app_setting_attrib_cmd();
2507 BTIF_TRACE_DEBUG("%s App setting not supported, complete procedure", __FUNCTION__);
2508 rc_ctrl_procedure_complete();
2512 else if (pmeta_msg->code == AVRC_RSP_CHANGED)
2514 btif_rc_supported_event_t *p_event;
2517 BTIF_TRACE_DEBUG("%s Notification completed : 0x%2X ", __FUNCTION__,
2520 node = list_begin(btif_rc_cb.rc_supported_event_list);
2521 while (node != NULL)
2523 p_event = (btif_rc_supported_event_t *)list_node(node);
2524 if ((p_event != NULL) && (p_event->event_id == p_rsp->event_id))
2526 p_event->status = eNOT_REGISTERED;
2527 register_for_event_notification(p_event);
2530 node = list_next (node);
2533 switch (p_rsp->event_id)
2535 case AVRC_EVT_PLAY_STATUS_CHANGE:
2536 /* Start timer to get play status periodically
2537 * if the play state is playing.
2539 if (p_rsp->param.play_status == AVRC_PLAYSTATE_PLAYING)
2541 rc_start_play_status_timer();
2545 rc_stop_play_status_timer();
2547 HAL_CBACK(bt_rc_ctrl_callbacks, play_status_changed_cb,
2548 &rc_addr, p_rsp->param.play_status);
2551 case AVRC_EVT_TRACK_CHANGE:
2552 if (rc_is_track_id_valid (p_rsp->param.track) != true)
2556 get_element_attribute_cmd (AVRC_MAX_NUM_MEDIA_ATTR_ID, attr_list);
2559 case AVRC_EVT_APP_SETTING_CHANGE:
2561 btrc_player_settings_t app_settings;
2564 app_settings.num_attr = p_rsp->param.player_setting.num_attr;
2565 for (xx = 0; xx < app_settings.num_attr; xx++)
2567 app_settings.attr_ids[xx] = p_rsp->param.player_setting.attr_id[xx];
2568 app_settings.attr_values[xx] = p_rsp->param.player_setting.attr_value[xx];
2570 HAL_CBACK(bt_rc_ctrl_callbacks, playerapplicationsetting_changed_cb,
2571 &rc_addr, &app_settings);
2575 case AVRC_EVT_NOW_PLAYING_CHANGE:
2578 case AVRC_EVT_AVAL_PLAYERS_CHANGE:
2581 case AVRC_EVT_ADDR_PLAYER_CHANGE:
2584 case AVRC_EVT_UIDS_CHANGE:
2587 case AVRC_EVT_TRACK_REACHED_END:
2588 case AVRC_EVT_TRACK_REACHED_START:
2589 case AVRC_EVT_PLAY_POS_CHANGED:
2590 case AVRC_EVT_BATTERY_STATUS_CHANGE:
2591 case AVRC_EVT_SYSTEM_STATUS_CHANGE:
2593 BTIF_TRACE_ERROR("%s Unhandled completion response 0x%2X",
2594 __FUNCTION__, p_rsp->event_id);
2600 /***************************************************************************
2602 ** Function handle_app_attr_response
2604 ** Description handles the the application attributes response and
2605 ** initiates procedure to fetch the attribute values
2608 ***************************************************************************/
2609 static void handle_app_attr_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_ATTR_RSP *p_rsp)
2613 if (p_rsp->status != AVRC_STS_NO_ERROR)
2615 BTIF_TRACE_ERROR("%s Error getting Player application settings: 0x%2X",
2616 __FUNCTION__, p_rsp->status);
2617 rc_ctrl_procedure_complete();
2621 for (xx = 0; xx < p_rsp->num_attr; xx++)
2625 if (p_rsp->attrs[xx] > AVRC_PLAYER_SETTING_LOW_MENU_EXT)
2627 st_index = btif_rc_cb.rc_app_settings.num_ext_attrs;
2628 btif_rc_cb.rc_app_settings.ext_attrs[st_index].attr_id = p_rsp->attrs[xx];
2629 btif_rc_cb.rc_app_settings.num_ext_attrs++;
2633 st_index = btif_rc_cb.rc_app_settings.num_attrs;
2634 btif_rc_cb.rc_app_settings.attrs[st_index].attr_id = p_rsp->attrs[xx];
2635 btif_rc_cb.rc_app_settings.num_attrs++;
2638 btif_rc_cb.rc_app_settings.attr_index = 0;
2639 btif_rc_cb.rc_app_settings.ext_attr_index = 0;
2640 btif_rc_cb.rc_app_settings.ext_val_index = 0;
2641 if (p_rsp->num_attr)
2643 list_player_app_setting_value_cmd (btif_rc_cb.rc_app_settings.attrs[0].attr_id);
2647 BTIF_TRACE_ERROR("%s No Player application settings found",
2652 /***************************************************************************
2654 ** Function handle_app_val_response
2656 ** Description handles the the attributes value response and if extended
2657 ** menu is available, it initiates query for the attribute
2658 ** text. If not, it initiates procedure to get the current
2659 ** attribute values and calls the HAL callback for provding
2660 ** application settings information.
2663 ***************************************************************************/
2664 static void handle_app_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_VALUES_RSP *p_rsp)
2666 UINT8 xx, attr_index;
2667 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2668 btif_rc_player_app_settings_t *p_app_settings;
2669 bt_bdaddr_t rc_addr;
2671 /* Todo: Do we need to retry on command timeout */
2672 if (p_rsp->status != AVRC_STS_NO_ERROR)
2674 BTIF_TRACE_ERROR("%s Error fetching attribute values 0x%02X",
2675 __FUNCTION__, p_rsp->status);
2679 p_app_settings = &btif_rc_cb.rc_app_settings;
2680 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2682 if (p_app_settings->attr_index < p_app_settings->num_attrs)
2684 attr_index = p_app_settings->attr_index;
2685 p_app_settings->attrs[attr_index].num_val = p_rsp->num_val;
2686 for (xx = 0; xx < p_rsp->num_val; xx++)
2688 p_app_settings->attrs[attr_index].attr_val[xx] = p_rsp->vals[xx];
2691 p_app_settings->attr_index++;
2692 if (attr_index < p_app_settings->num_attrs)
2694 list_player_app_setting_value_cmd (p_app_settings->attrs[p_app_settings->attr_index].attr_id);
2696 else if (p_app_settings->ext_attr_index < p_app_settings->num_ext_attrs)
2699 p_app_settings->ext_attr_index = 0;
2700 list_player_app_setting_value_cmd (p_app_settings->ext_attrs[attr_index].attr_id);
2704 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2706 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2708 get_player_app_setting_cmd (p_app_settings->num_attrs, attrs);
2709 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2710 p_app_settings->num_attrs, p_app_settings->attrs, 0, NULL);
2713 else if (p_app_settings->ext_attr_index < p_app_settings->num_ext_attrs)
2715 attr_index = p_app_settings->ext_attr_index;
2716 p_app_settings->ext_attrs[attr_index].num_val = p_rsp->num_val;
2717 for (xx = 0; xx < p_rsp->num_val; xx++)
2719 p_app_settings->ext_attrs[attr_index].ext_attr_val[xx].val = p_rsp->vals[xx];
2722 p_app_settings->ext_attr_index++;
2723 if (attr_index < p_app_settings->num_ext_attrs)
2725 list_player_app_setting_value_cmd (p_app_settings->ext_attrs[p_app_settings->ext_attr_index].attr_id);
2729 UINT8 attr[AVRC_MAX_APP_ATTR_SIZE];
2732 for (xx = 0; xx < p_app_settings->num_ext_attrs; xx++)
2734 attr[xx] = p_app_settings->ext_attrs[xx].attr_id;
2736 get_player_app_setting_attr_text_cmd(attr, xx);
2741 /***************************************************************************
2743 ** Function handle_app_cur_val_response
2745 ** Description handles the the get attributes value response.
2749 ***************************************************************************/
2750 static void handle_app_cur_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp)
2752 btrc_player_settings_t app_settings;
2753 bt_bdaddr_t rc_addr;
2756 /* Todo: Do we need to retry on command timeout */
2757 if (p_rsp->status != AVRC_STS_NO_ERROR)
2759 BTIF_TRACE_ERROR("%s Error fetching current settings: 0x%02X",
2760 __FUNCTION__, p_rsp->status);
2764 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2766 app_settings.num_attr = p_rsp->num_val;
2767 for (xx = 0; xx < app_settings.num_attr; xx++)
2769 app_settings.attr_ids[xx] = p_rsp->p_vals[xx].attr_id;
2770 app_settings.attr_values[xx] = p_rsp->p_vals[xx].attr_val;
2772 HAL_CBACK(bt_rc_ctrl_callbacks, playerapplicationsetting_changed_cb,
2773 &rc_addr, &app_settings);
2774 /* Application settings are fetched only once for initial values
2775 * initiate anything that follows after RC procedure.
2776 * Defer it if browsing is supported till players query
2778 rc_ctrl_procedure_complete ();
2779 osi_free_and_reset((void **)&p_rsp->p_vals);
2782 /***************************************************************************
2784 ** Function handle_app_attr_txt_response
2786 ** Description handles the the get attributes text response, if fails
2787 ** calls HAL callback with just normal settings and initiates
2788 ** query for current settings else initiates query for value text
2791 ***************************************************************************/
2792 static void handle_app_attr_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp)
2795 UINT8 vals[AVRC_MAX_APP_ATTR_SIZE];
2796 btif_rc_player_app_settings_t *p_app_settings;
2797 bt_bdaddr_t rc_addr;
2799 p_app_settings = &btif_rc_cb.rc_app_settings;
2800 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2802 /* Todo: Do we need to retry on command timeout */
2803 if (p_rsp->status != AVRC_STS_NO_ERROR)
2805 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2807 BTIF_TRACE_ERROR("%s Error fetching attribute text: 0x%02X",
2808 __FUNCTION__, p_rsp->status);
2809 /* Not able to fetch Text for extended Menu, skip the process
2810 * and cleanup used memory. Proceed to get the current settings
2811 * for standard attributes.
2813 p_app_settings->num_ext_attrs = 0;
2814 for (xx = 0; xx < p_app_settings->ext_attr_index; xx++)
2815 osi_free_and_reset((void **)&p_app_settings->ext_attrs[xx].p_str);
2816 p_app_settings->ext_attr_index = 0;
2818 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2820 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2822 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2823 p_app_settings->num_attrs, p_app_settings->attrs, 0, NULL);
2825 get_player_app_setting_cmd (xx, attrs);
2829 for (xx = 0; xx < p_rsp->num_attr; xx++)
2832 for (x = 0; x < p_app_settings->num_ext_attrs; x++)
2834 if (p_app_settings->ext_attrs[x].attr_id == p_rsp->p_attrs[xx].attr_id)
2836 p_app_settings->ext_attrs[x].charset_id = p_rsp->p_attrs[xx].charset_id;
2837 p_app_settings->ext_attrs[x].str_len = p_rsp->p_attrs[xx].str_len;
2838 p_app_settings->ext_attrs[x].p_str = p_rsp->p_attrs[xx].p_str;
2844 for (xx = 0; xx < p_app_settings->ext_attrs[0].num_val; xx++)
2846 vals[xx] = p_app_settings->ext_attrs[0].ext_attr_val[xx].val;
2848 get_player_app_setting_value_text_cmd(vals, xx);
2852 /***************************************************************************
2854 ** Function handle_app_attr_val_txt_response
2856 ** Description handles the the get attributes value text response, if fails
2857 ** calls HAL callback with just normal settings and initiates
2858 ** query for current settings
2861 ***************************************************************************/
2862 static void handle_app_attr_val_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp)
2864 UINT8 xx, attr_index;
2865 UINT8 vals[AVRC_MAX_APP_ATTR_SIZE];
2866 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2867 btif_rc_player_app_settings_t *p_app_settings;
2868 bt_bdaddr_t rc_addr;
2870 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2871 p_app_settings = &btif_rc_cb.rc_app_settings;
2873 /* Todo: Do we need to retry on command timeout */
2874 if (p_rsp->status != AVRC_STS_NO_ERROR)
2876 UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
2878 BTIF_TRACE_ERROR("%s Error fetching attribute value text: 0x%02X",
2879 __FUNCTION__, p_rsp->status);
2881 /* Not able to fetch Text for extended Menu, skip the process
2882 * and cleanup used memory. Proceed to get the current settings
2883 * for standard attributes.
2885 p_app_settings->num_ext_attrs = 0;
2886 for (xx = 0; xx < p_app_settings->ext_attr_index; xx++)
2889 btrc_player_app_ext_attr_t *p_ext_attr = &p_app_settings->ext_attrs[xx];
2891 for (x = 0; x < p_ext_attr->num_val; x++)
2892 osi_free_and_reset((void **)&p_ext_attr->ext_attr_val[x].p_str);
2893 p_ext_attr->num_val = 0;
2894 osi_free_and_reset((void **)&p_app_settings->ext_attrs[xx].p_str);
2896 p_app_settings->ext_attr_index = 0;
2898 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2900 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2902 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2903 p_app_settings->num_attrs, p_app_settings->attrs, 0, NULL);
2905 get_player_app_setting_cmd (xx, attrs);
2909 for (xx = 0; xx < p_rsp->num_attr; xx++)
2912 btrc_player_app_ext_attr_t *p_ext_attr;
2913 p_ext_attr = &p_app_settings->ext_attrs[p_app_settings->ext_val_index];
2914 for (x = 0; x < p_rsp->num_attr; x++)
2916 if (p_ext_attr->ext_attr_val[x].val == p_rsp->p_attrs[xx].attr_id)
2918 p_ext_attr->ext_attr_val[x].charset_id = p_rsp->p_attrs[xx].charset_id;
2919 p_ext_attr->ext_attr_val[x].str_len = p_rsp->p_attrs[xx].str_len;
2920 p_ext_attr->ext_attr_val[x].p_str = p_rsp->p_attrs[xx].p_str;
2925 p_app_settings->ext_val_index++;
2927 if (p_app_settings->ext_val_index < p_app_settings->num_ext_attrs)
2929 attr_index = p_app_settings->ext_val_index;
2930 for (xx = 0; xx < p_app_settings->ext_attrs[attr_index].num_val; xx++)
2932 vals[xx] = p_app_settings->ext_attrs[attr_index].ext_attr_val[xx].val;
2934 get_player_app_setting_value_text_cmd(vals, xx);
2940 for (xx = 0; xx < p_app_settings->num_attrs; xx++)
2942 attrs[xx] = p_app_settings->attrs[xx].attr_id;
2944 for (x = 0; x < p_app_settings->num_ext_attrs; x++)
2946 attrs[xx+x] = p_app_settings->ext_attrs[x].attr_id;
2948 HAL_CBACK (bt_rc_ctrl_callbacks, playerapplicationsetting_cb, &rc_addr,
2949 p_app_settings->num_attrs, p_app_settings->attrs,
2950 p_app_settings->num_ext_attrs, p_app_settings->ext_attrs);
2951 get_player_app_setting_cmd (xx + x, attrs);
2953 /* Free the application settings information after sending to
2956 for (xx = 0; xx < p_app_settings->ext_attr_index; xx++)
2959 btrc_player_app_ext_attr_t *p_ext_attr = &p_app_settings->ext_attrs[xx];
2961 for (x = 0; x < p_ext_attr->num_val; x++)
2962 osi_free_and_reset((void **)&p_ext_attr->ext_attr_val[x].p_str);
2963 p_ext_attr->num_val = 0;
2964 osi_free_and_reset((void **)&p_app_settings->ext_attrs[xx].p_str);
2966 p_app_settings->num_attrs = 0;
2970 /***************************************************************************
2972 ** Function handle_set_app_attr_val_response
2974 ** Description handles the the set attributes value response, if fails
2975 ** calls HAL callback to indicate the failure
2978 ***************************************************************************/
2979 static void handle_set_app_attr_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_RSP *p_rsp)
2981 uint8_t accepted = 0;
2982 bt_bdaddr_t rc_addr;
2984 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
2986 /* For timeout pmeta_msg will be NULL, else we need to
2987 * check if this is accepted by TG
2989 if (pmeta_msg && (pmeta_msg->code == AVRC_RSP_ACCEPT))
2993 HAL_CBACK(bt_rc_ctrl_callbacks, setplayerappsetting_rsp_cb, &rc_addr, accepted);
2996 /***************************************************************************
2998 ** Function handle_get_elem_attr_response
3000 ** Description handles the the element attributes response, calls
3001 ** HAL callback to update track change information.
3004 ***************************************************************************/
3005 static void handle_get_elem_attr_response (tBTA_AV_META_MSG *pmeta_msg,
3006 tAVRC_GET_ELEM_ATTRS_RSP *p_rsp)
3008 if (p_rsp->status == AVRC_STS_NO_ERROR) {
3009 bt_bdaddr_t rc_addr;
3010 size_t buf_size = p_rsp->num_attr * sizeof(btrc_element_attr_val_t);
3011 btrc_element_attr_val_t *p_attr =
3012 (btrc_element_attr_val_t *)osi_calloc(buf_size);
3014 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
3016 for (int i = 0; i < p_rsp->num_attr; i++) {
3017 p_attr[i].attr_id = p_rsp->p_attrs[i].attr_id;
3018 /* Todo. Legth limit check to include null */
3019 if (p_rsp->p_attrs[i].name.str_len &&
3020 p_rsp->p_attrs[i].name.p_str) {
3021 memcpy(p_attr[i].text, p_rsp->p_attrs[i].name.p_str,
3022 p_rsp->p_attrs[i].name.str_len);
3023 osi_free_and_reset((void **)&p_rsp->p_attrs[i].name.p_str);
3026 HAL_CBACK(bt_rc_ctrl_callbacks, track_changed_cb,
3027 &rc_addr, p_rsp->num_attr, p_attr);
3029 } else if (p_rsp->status == BTIF_RC_STS_TIMEOUT) {
3030 /* Retry for timeout case, this covers error handling
3031 * for continuation failure also.
3033 UINT32 attr_list[] = {
3034 AVRC_MEDIA_ATTR_ID_TITLE,
3035 AVRC_MEDIA_ATTR_ID_ARTIST,
3036 AVRC_MEDIA_ATTR_ID_ALBUM,
3037 AVRC_MEDIA_ATTR_ID_TRACK_NUM,
3038 AVRC_MEDIA_ATTR_ID_NUM_TRACKS,
3039 AVRC_MEDIA_ATTR_ID_GENRE,
3040 AVRC_MEDIA_ATTR_ID_PLAYING_TIME
3042 get_element_attribute_cmd (AVRC_MAX_NUM_MEDIA_ATTR_ID, attr_list);
3044 BTIF_TRACE_ERROR("%s: Error in get element attr procedure %d",
3045 __func__, p_rsp->status);
3049 /***************************************************************************
3051 ** Function handle_get_playstatus_response
3053 ** Description handles the the play status response, calls
3054 ** HAL callback to update play position.
3057 ***************************************************************************/
3058 static void handle_get_playstatus_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_PLAY_STATUS_RSP *p_rsp)
3060 bt_bdaddr_t rc_addr;
3062 bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
3064 if (p_rsp->status == AVRC_STS_NO_ERROR)
3066 HAL_CBACK(bt_rc_ctrl_callbacks, play_position_changed_cb,
3067 &rc_addr, p_rsp->song_len, p_rsp->song_pos);
3071 BTIF_TRACE_ERROR("%s: Error in get play status procedure %d",
3072 __FUNCTION__, p_rsp->status);
3076 /***************************************************************************
3078 ** Function clear_cmd_timeout
3080 ** Description helper function to stop the command timeout timer
3083 ***************************************************************************/
3084 static void clear_cmd_timeout (UINT8 label)
3086 rc_transaction_t *p_txn;
3088 p_txn = get_transaction_by_lbl (label);
3091 BTIF_TRACE_ERROR("%s: Error in transaction label lookup", __FUNCTION__);
3095 if (p_txn->txn_timer != NULL)
3096 alarm_cancel(p_txn->txn_timer);
3099 /***************************************************************************
3101 ** Function handle_avk_rc_metamsg_rsp
3103 ** Description Handle RC metamessage response
3107 ***************************************************************************/
3108 static void handle_avk_rc_metamsg_rsp(tBTA_AV_META_MSG *pmeta_msg)
3110 tAVRC_RESPONSE avrc_response = {0};
3111 UINT8 scratch_buf[512] = {0};// this variable is unused
3115 BTIF_TRACE_DEBUG("%s opcode = %d rsp_code = %d ", __FUNCTION__,
3116 pmeta_msg->p_msg->hdr.opcode, pmeta_msg->code);
3118 if ((AVRC_OP_VENDOR == pmeta_msg->p_msg->hdr.opcode)&&
3119 (pmeta_msg->code >= AVRC_RSP_NOT_IMPL)&&
3120 (pmeta_msg->code <= AVRC_RSP_INTERIM))
3122 status = AVRC_Ctrl_ParsResponse(pmeta_msg->p_msg, &avrc_response, scratch_buf, &buf_len);
3123 BTIF_TRACE_DEBUG("%s parse status %d pdu = %d rsp_status = %d",
3124 __FUNCTION__, status, avrc_response.pdu,
3125 pmeta_msg->p_msg->vendor.hdr.ctype);
3127 switch (avrc_response.pdu)
3129 case AVRC_PDU_REGISTER_NOTIFICATION:
3130 handle_notification_response(pmeta_msg, &avrc_response.reg_notif);
3131 if (pmeta_msg->code == AVRC_RSP_INTERIM)
3133 /* Don't free the transaction Id */
3134 clear_cmd_timeout (pmeta_msg->label);
3139 case AVRC_PDU_GET_CAPABILITIES:
3140 handle_get_capability_response(pmeta_msg, &avrc_response.get_caps);
3143 case AVRC_PDU_LIST_PLAYER_APP_ATTR:
3144 handle_app_attr_response(pmeta_msg, &avrc_response.list_app_attr);
3147 case AVRC_PDU_LIST_PLAYER_APP_VALUES:
3148 handle_app_val_response(pmeta_msg, &avrc_response.list_app_values);
3151 case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
3152 handle_app_cur_val_response(pmeta_msg, &avrc_response.get_cur_app_val);
3155 case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
3156 handle_app_attr_txt_response(pmeta_msg, &avrc_response.get_app_attr_txt);
3159 case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
3160 handle_app_attr_val_txt_response(pmeta_msg, &avrc_response.get_app_val_txt);
3163 case AVRC_PDU_SET_PLAYER_APP_VALUE:
3164 handle_set_app_attr_val_response(pmeta_msg, &avrc_response.set_app_val);
3167 case AVRC_PDU_GET_ELEMENT_ATTR:
3168 handle_get_elem_attr_response(pmeta_msg, &avrc_response.get_elem_attrs);
3171 case AVRC_PDU_GET_PLAY_STATUS:
3172 handle_get_playstatus_response(pmeta_msg, &avrc_response.get_play_status);
3175 release_transaction(pmeta_msg->label);
3179 BTIF_TRACE_DEBUG("%s:Invalid Vendor Command code: %d len: %d. Not processing it.",
3180 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
3185 /***************************************************************************
3187 ** Function handle_avk_rc_metamsg_cmd
3189 ** Description Handle RC metamessage response
3193 ***************************************************************************/
3194 static void handle_avk_rc_metamsg_cmd(tBTA_AV_META_MSG *pmeta_msg)
3196 tAVRC_COMMAND avrc_cmd = {0};
3197 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3198 BTIF_TRACE_DEBUG("%s opcode = %d rsp_code = %d ",__FUNCTION__,
3199 pmeta_msg->p_msg->hdr.opcode,pmeta_msg->code);
3200 if ((AVRC_OP_VENDOR==pmeta_msg->p_msg->hdr.opcode)&&
3201 (pmeta_msg->code <= AVRC_CMD_GEN_INQ))
3203 status = AVRC_Ctrl_ParsCommand(pmeta_msg->p_msg, &avrc_cmd);
3204 BTIF_TRACE_DEBUG("%s Received vendor command.code %d, PDU %d label %d",
3205 __FUNCTION__, pmeta_msg->code, avrc_cmd.pdu, pmeta_msg->label);
3207 if (status != AVRC_STS_NO_ERROR)
3210 BTIF_TRACE_WARNING("%s: Error in parsing received metamsg command. status: 0x%02x",
3211 __FUNCTION__, status);
3212 send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_cmd.pdu, status);
3216 if (avrc_cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION)
3218 UINT8 event_id = avrc_cmd.reg_notif.event_id;
3219 BTIF_TRACE_EVENT("%s:Register notification event_id: %s",
3220 __FUNCTION__, dump_rc_notification_event_id(event_id));
3222 else if (avrc_cmd.pdu == AVRC_PDU_SET_ABSOLUTE_VOLUME)
3224 BTIF_TRACE_EVENT("%s: Abs Volume Cmd Recvd", __FUNCTION__);
3226 btif_rc_ctrl_upstreams_rsp_cmd(avrc_cmd.pdu, &avrc_cmd, pmeta_msg->label);
3231 BTIF_TRACE_DEBUG("%s:Invalid Vendor Command code: %d len: %d. Not processing it.",
3232 __FUNCTION__, pmeta_msg->code, pmeta_msg->len);
3238 /***************************************************************************
3242 ** Description Closes the AVRC interface
3246 ***************************************************************************/
3247 static void cleanup()
3249 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
3251 if (bt_rc_callbacks)
3253 bt_rc_callbacks = NULL;
3255 alarm_free(btif_rc_cb.rc_play_status_timer);
3256 memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
3258 BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
3261 /***************************************************************************
3263 ** Function cleanup_ctrl
3265 ** Description Closes the AVRC Controller interface
3269 ***************************************************************************/
3270 static void cleanup_ctrl()
3272 BTIF_TRACE_EVENT("## %s ##", __FUNCTION__);
3274 if (bt_rc_ctrl_callbacks)
3276 bt_rc_ctrl_callbacks = NULL;
3278 alarm_free(btif_rc_cb.rc_play_status_timer);
3279 memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
3281 BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
3284 /***************************************************************************
3286 ** Function getcapabilities_cmd
3288 ** Description GetCapabilties from Remote(Company_ID, Events_Supported)
3292 ***************************************************************************/
3293 static bt_status_t getcapabilities_cmd (uint8_t cap_id)
3295 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3296 rc_transaction_t *p_transaction = NULL;
3297 #if (AVRC_CTLR_INCLUDED == TRUE)
3298 BTIF_TRACE_DEBUG("%s: cap_id %d", __FUNCTION__, cap_id);
3300 bt_status_t tran_status=get_transaction(&p_transaction);
3301 if (BT_STATUS_SUCCESS != tran_status)
3302 return BT_STATUS_FAIL;
3304 tAVRC_COMMAND avrc_cmd = {0};
3305 BT_HDR *p_msg = NULL;
3306 avrc_cmd.get_caps.opcode = AVRC_OP_VENDOR;
3307 avrc_cmd.get_caps.capability_id = cap_id;
3308 avrc_cmd.get_caps.pdu = AVRC_PDU_GET_CAPABILITIES;
3309 avrc_cmd.get_caps.status = AVRC_STS_NO_ERROR;
3310 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3311 if ((status == AVRC_STS_NO_ERROR)&&(p_msg != NULL))
3313 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3314 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3315 __FUNCTION__,p_transaction->lbl);
3316 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3317 data_start, p_msg->len);
3318 status = BT_STATUS_SUCCESS;
3319 start_status_command_timer (AVRC_PDU_GET_CAPABILITIES, p_transaction);
3323 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3324 __FUNCTION__, status);
3328 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3333 /***************************************************************************
3335 ** Function list_player_app_setting_attrib_cmd
3337 ** Description Get supported List Player Attributes
3341 ***************************************************************************/
3342 static bt_status_t list_player_app_setting_attrib_cmd(void)
3344 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3345 rc_transaction_t *p_transaction = NULL;
3346 #if (AVRC_CTLR_INCLUDED == TRUE)
3347 BTIF_TRACE_DEBUG("%s: ", __FUNCTION__);
3349 bt_status_t tran_status=get_transaction(&p_transaction);
3350 if (BT_STATUS_SUCCESS != tran_status)
3351 return BT_STATUS_FAIL;
3353 tAVRC_COMMAND avrc_cmd = {0};
3354 BT_HDR *p_msg = NULL;
3355 avrc_cmd.list_app_attr.opcode = AVRC_OP_VENDOR;
3356 avrc_cmd.list_app_attr.pdu = AVRC_PDU_LIST_PLAYER_APP_ATTR;
3357 avrc_cmd.list_app_attr.status = AVRC_STS_NO_ERROR;
3358 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3359 if ((status == AVRC_STS_NO_ERROR)&&(p_msg != NULL))
3361 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3362 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3363 __FUNCTION__,p_transaction->lbl);
3364 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3365 data_start, p_msg->len);
3366 status = BT_STATUS_SUCCESS;
3367 start_status_command_timer (AVRC_PDU_LIST_PLAYER_APP_ATTR, p_transaction);
3372 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3373 __FUNCTION__, status);
3377 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3382 /***************************************************************************
3384 ** Function list_player_app_setting_value_cmd
3386 ** Description Get values of supported Player Attributes
3390 ***************************************************************************/
3391 static bt_status_t list_player_app_setting_value_cmd(uint8_t attrib_id)
3393 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3394 rc_transaction_t *p_transaction=NULL;
3395 #if (AVRC_CTLR_INCLUDED == TRUE)
3396 BTIF_TRACE_DEBUG("%s: attrib_id %d", __FUNCTION__, attrib_id);
3398 bt_status_t tran_status=get_transaction(&p_transaction);
3399 if (BT_STATUS_SUCCESS != tran_status)
3400 return BT_STATUS_FAIL;
3402 tAVRC_COMMAND avrc_cmd = {0};
3403 BT_HDR *p_msg = NULL;
3404 avrc_cmd.list_app_values.attr_id = attrib_id;
3405 avrc_cmd.list_app_values.opcode = AVRC_OP_VENDOR;
3406 avrc_cmd.list_app_values.pdu = AVRC_PDU_LIST_PLAYER_APP_VALUES;
3407 avrc_cmd.list_app_values.status = AVRC_STS_NO_ERROR;
3408 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3409 if ((status == AVRC_STS_NO_ERROR) && (p_msg != NULL))
3411 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3412 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3413 __FUNCTION__,p_transaction->lbl);
3414 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3415 data_start, p_msg->len);
3416 status = BT_STATUS_SUCCESS;
3417 start_status_command_timer (AVRC_PDU_LIST_PLAYER_APP_VALUES, p_transaction);
3421 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x", __FUNCTION__, status);
3425 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3430 /***************************************************************************
3432 ** Function get_player_app_setting_cmd
3434 ** Description Get current values of Player Attributes
3438 ***************************************************************************/
3439 static bt_status_t get_player_app_setting_cmd(uint8_t num_attrib, uint8_t* attrib_ids)
3441 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3442 rc_transaction_t *p_transaction = NULL;
3444 #if (AVRC_CTLR_INCLUDED == TRUE)
3445 BTIF_TRACE_DEBUG("%s: num attrib_id %d", __FUNCTION__, num_attrib);
3447 bt_status_t tran_status=get_transaction(&p_transaction);
3448 if (BT_STATUS_SUCCESS != tran_status)
3449 return BT_STATUS_FAIL;
3451 tAVRC_COMMAND avrc_cmd = {0};
3452 BT_HDR *p_msg = NULL;
3453 avrc_cmd.get_cur_app_val.opcode = AVRC_OP_VENDOR;
3454 avrc_cmd.get_cur_app_val.status = AVRC_STS_NO_ERROR;
3455 avrc_cmd.get_cur_app_val.num_attr = num_attrib;
3456 avrc_cmd.get_cur_app_val.pdu = AVRC_PDU_GET_CUR_PLAYER_APP_VALUE;
3458 for (count = 0; count < num_attrib; count++)
3460 avrc_cmd.get_cur_app_val.attrs[count] = attrib_ids[count];
3462 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3463 if ((status == AVRC_STS_NO_ERROR) && (p_msg != NULL))
3465 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3466 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3467 __FUNCTION__,p_transaction->lbl);
3468 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_STATUS,
3469 data_start, p_msg->len);
3470 status = BT_STATUS_SUCCESS;
3471 start_status_command_timer (AVRC_PDU_GET_CUR_PLAYER_APP_VALUE, p_transaction);
3475 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3476 __FUNCTION__, status);
3480 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3485 /***************************************************************************
3487 ** Function change_player_app_setting
3489 ** Description Set current values of Player Attributes
3493 ***************************************************************************/
3494 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)
3496 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3497 rc_transaction_t *p_transaction = NULL;
3499 #if (AVRC_CTLR_INCLUDED == TRUE)
3500 BTIF_TRACE_DEBUG("%s: num attrib_id %d", __FUNCTION__, num_attrib);
3502 bt_status_t tran_status=get_transaction(&p_transaction);
3503 if (BT_STATUS_SUCCESS != tran_status)
3504 return BT_STATUS_FAIL;
3506 tAVRC_COMMAND avrc_cmd = {0};
3507 BT_HDR *p_msg = NULL;
3508 avrc_cmd.set_app_val.opcode = AVRC_OP_VENDOR;
3509 avrc_cmd.set_app_val.status = AVRC_STS_NO_ERROR;
3510 avrc_cmd.set_app_val.num_val = num_attrib;
3511 avrc_cmd.set_app_val.pdu = AVRC_PDU_SET_PLAYER_APP_VALUE;
3512 avrc_cmd.set_app_val.p_vals =
3513 (tAVRC_APP_SETTING *)osi_malloc(sizeof(tAVRC_APP_SETTING) * num_attrib);
3514 for (count = 0; count < num_attrib; count++)
3516 avrc_cmd.set_app_val.p_vals[count].attr_id = attrib_ids[count];
3517 avrc_cmd.set_app_val.p_vals[count].attr_val = attrib_vals[count];
3519 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3520 if ((status == AVRC_STS_NO_ERROR) && (p_msg != NULL))
3522 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3523 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3524 __FUNCTION__,p_transaction->lbl);
3525 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,AVRC_CMD_CTRL,
3526 data_start, p_msg->len);
3527 status = BT_STATUS_SUCCESS;
3528 start_control_command_timer (AVRC_PDU_SET_PLAYER_APP_VALUE, p_transaction);
3532 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3533 __FUNCTION__, status);
3536 osi_free_and_reset((void **)&avrc_cmd.set_app_val.p_vals);
3538 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3543 /***************************************************************************
3545 ** Function get_player_app_setting_attr_text_cmd
3547 ** Description Get text description for app attribute
3551 ***************************************************************************/
3552 static bt_status_t get_player_app_setting_attr_text_cmd (UINT8 *attrs, UINT8 num_attrs)
3554 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3555 rc_transaction_t *p_transaction = NULL;
3557 #if (AVRC_CTLR_INCLUDED == TRUE)
3558 tAVRC_COMMAND avrc_cmd = {0};
3559 BT_HDR *p_msg = NULL;
3560 bt_status_t tran_status;
3563 BTIF_TRACE_DEBUG("%s: num attrs %d", __FUNCTION__, num_attrs);
3565 tran_status = get_transaction(&p_transaction);
3566 if (BT_STATUS_SUCCESS != tran_status)
3567 return BT_STATUS_FAIL;
3569 avrc_cmd.pdu = AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT;
3570 avrc_cmd.get_app_attr_txt.opcode = AVRC_OP_VENDOR;
3571 avrc_cmd.get_app_attr_txt.num_attr = num_attrs;
3573 for (count = 0; count < num_attrs; count++)
3575 avrc_cmd.get_app_attr_txt.attrs[count] = attrs[count];
3577 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3578 if (status == AVRC_STS_NO_ERROR)
3580 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3581 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3582 __FUNCTION__, p_transaction->lbl);
3583 BTA_AvVendorCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3584 AVRC_CMD_STATUS, data_start, p_msg->len);
3586 status = BT_STATUS_SUCCESS;
3587 start_status_command_timer (AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT, p_transaction);
3591 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x", __FUNCTION__, status);
3595 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3600 /***************************************************************************
3602 ** Function get_player_app_setting_val_text_cmd
3604 ** Description Get text description for app attribute values
3608 ***************************************************************************/
3609 static bt_status_t get_player_app_setting_value_text_cmd (UINT8 *vals, UINT8 num_vals)
3611 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3612 rc_transaction_t *p_transaction = NULL;
3614 #if (AVRC_CTLR_INCLUDED == TRUE)
3615 tAVRC_COMMAND avrc_cmd = {0};
3616 BT_HDR *p_msg = NULL;
3617 bt_status_t tran_status;
3620 BTIF_TRACE_DEBUG("%s: num_vals %d", __FUNCTION__, num_vals);
3622 tran_status = get_transaction(&p_transaction);
3623 if (BT_STATUS_SUCCESS != tran_status)
3624 return BT_STATUS_FAIL;
3626 avrc_cmd.pdu = AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT;
3627 avrc_cmd.get_app_val_txt.opcode = AVRC_OP_VENDOR;
3628 avrc_cmd.get_app_val_txt.num_val = num_vals;
3630 for (count = 0; count < num_vals; count++)
3632 avrc_cmd.get_app_val_txt.vals[count] = vals[count];
3634 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3635 if (status == AVRC_STS_NO_ERROR)
3637 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3638 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3639 __FUNCTION__, p_transaction->lbl);
3642 BTA_AvVendorCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3643 AVRC_CMD_STATUS, data_start, p_msg->len);
3644 status = BT_STATUS_SUCCESS;
3645 start_status_command_timer (AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT, p_transaction);
3650 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3651 __FUNCTION__, status);
3655 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3660 /***************************************************************************
3662 ** Function register_notification_cmd
3664 ** Description Send Command to register for a Notification ID
3668 ***************************************************************************/
3669 static bt_status_t register_notification_cmd (UINT8 label, UINT8 event_id, UINT32 event_value)
3672 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3673 #if (AVRC_CTLR_INCLUDED == TRUE)
3674 tAVRC_COMMAND avrc_cmd = {0};
3675 BT_HDR *p_msg = NULL;
3679 BTIF_TRACE_DEBUG("%s: event_id %d event_value", __FUNCTION__, event_id, event_value);
3681 avrc_cmd.reg_notif.opcode = AVRC_OP_VENDOR;
3682 avrc_cmd.reg_notif.status = AVRC_STS_NO_ERROR;
3683 avrc_cmd.reg_notif.event_id = event_id;
3684 avrc_cmd.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
3685 avrc_cmd.reg_notif.param = event_value;
3686 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3687 if (status == AVRC_STS_NO_ERROR)
3689 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3690 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3691 __FUNCTION__, label);
3694 BTA_AvVendorCmd(btif_rc_cb.rc_handle, label, AVRC_CMD_NOTIF,
3695 data_start, p_msg->len);
3696 status = BT_STATUS_SUCCESS;
3701 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3702 __FUNCTION__, status);
3706 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3711 /***************************************************************************
3713 ** Function get_element_attribute_cmd
3715 ** Description Get Element Attribute for attributeIds
3719 ***************************************************************************/
3720 static bt_status_t get_element_attribute_cmd (uint8_t num_attribute, uint32_t *p_attr_ids)
3722 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3723 rc_transaction_t *p_transaction=NULL;
3725 #if (AVRC_CTLR_INCLUDED == TRUE)
3726 tAVRC_COMMAND avrc_cmd = {0};
3727 BT_HDR *p_msg = NULL;
3728 bt_status_t tran_status;
3731 BTIF_TRACE_DEBUG("%s: num_attribute %d attribute_id %d",
3732 __FUNCTION__, num_attribute, p_attr_ids[0]);
3734 tran_status = get_transaction(&p_transaction);
3735 if (BT_STATUS_SUCCESS != tran_status)
3736 return BT_STATUS_FAIL;
3738 avrc_cmd.get_elem_attrs.opcode = AVRC_OP_VENDOR;
3739 avrc_cmd.get_elem_attrs.status = AVRC_STS_NO_ERROR;
3740 avrc_cmd.get_elem_attrs.num_attr = num_attribute;
3741 avrc_cmd.get_elem_attrs.pdu = AVRC_PDU_GET_ELEMENT_ATTR;
3742 for (count = 0; count < num_attribute; count++)
3744 avrc_cmd.get_elem_attrs.attrs[count] = p_attr_ids[count];
3747 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3748 if (status == AVRC_STS_NO_ERROR)
3750 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3751 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3752 __FUNCTION__, p_transaction->lbl);
3755 BTA_AvVendorCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3756 AVRC_CMD_STATUS, data_start, p_msg->len);
3757 status = BT_STATUS_SUCCESS;
3758 start_status_command_timer (AVRC_PDU_GET_ELEMENT_ATTR,
3764 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3765 __FUNCTION__, status);
3769 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3774 /***************************************************************************
3776 ** Function get_play_status_cmd
3778 ** Description Get Element Attribute for attributeIds
3782 ***************************************************************************/
3783 static bt_status_t get_play_status_cmd(void)
3785 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3786 rc_transaction_t *p_transaction = NULL;
3787 #if (AVRC_CTLR_INCLUDED == TRUE)
3788 tAVRC_COMMAND avrc_cmd = {0};
3789 BT_HDR *p_msg = NULL;
3790 bt_status_t tran_status;
3793 BTIF_TRACE_DEBUG("%s: ", __FUNCTION__);
3794 tran_status = get_transaction(&p_transaction);
3795 if (BT_STATUS_SUCCESS != tran_status)
3796 return BT_STATUS_FAIL;
3798 avrc_cmd.get_play_status.opcode = AVRC_OP_VENDOR;
3799 avrc_cmd.get_play_status.pdu = AVRC_PDU_GET_PLAY_STATUS;
3800 avrc_cmd.get_play_status.status = AVRC_STS_NO_ERROR;
3801 status = AVRC_BldCommand(&avrc_cmd, &p_msg);
3802 if (status == AVRC_STS_NO_ERROR)
3804 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3805 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3806 __FUNCTION__, p_transaction->lbl);
3809 BTA_AvVendorCmd(btif_rc_cb.rc_handle,p_transaction->lbl,
3810 AVRC_CMD_STATUS, data_start, p_msg->len);
3811 status = BT_STATUS_SUCCESS;
3812 start_status_command_timer (AVRC_PDU_GET_PLAY_STATUS, p_transaction);
3817 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3818 __FUNCTION__, status);
3822 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3828 /***************************************************************************
3830 ** Function set_volume_rsp
3832 ** Description Rsp for SetAbsoluteVolume Command
3836 ***************************************************************************/
3837 static bt_status_t set_volume_rsp(bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label)
3839 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3840 #if (AVRC_CTLR_INCLUDED == TRUE)
3841 tAVRC_RESPONSE avrc_rsp;
3842 BT_HDR *p_msg = NULL;
3845 BTIF_TRACE_DEBUG("%s: abs_vol %d", __FUNCTION__, abs_vol);
3847 avrc_rsp.volume.opcode = AVRC_OP_VENDOR;
3848 avrc_rsp.volume.pdu = AVRC_PDU_SET_ABSOLUTE_VOLUME;
3849 avrc_rsp.volume.status = AVRC_STS_NO_ERROR;
3850 avrc_rsp.volume.volume = abs_vol;
3851 status = AVRC_BldResponse(btif_rc_cb.rc_handle, &avrc_rsp, &p_msg);
3852 if (status == AVRC_STS_NO_ERROR)
3854 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3855 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3856 __FUNCTION__, btif_rc_cb.rc_vol_label);
3859 BTA_AvVendorRsp(btif_rc_cb.rc_handle, label,
3860 BTA_AV_RSP_ACCEPT, data_start, p_msg->len, 0);
3861 status = BT_STATUS_SUCCESS;
3866 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3867 __FUNCTION__, status);
3871 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3876 /***************************************************************************
3878 ** Function send_register_abs_vol_rsp
3880 ** Description Rsp for Notification of Absolute Volume
3884 ***************************************************************************/
3885 static bt_status_t volume_change_notification_rsp(bt_bdaddr_t *bd_addr, btrc_notification_type_t rsp_type,
3886 uint8_t abs_vol, uint8_t label)
3888 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3889 tAVRC_RESPONSE avrc_rsp;
3890 BT_HDR *p_msg = NULL;
3891 #if (AVRC_CTLR_INCLUDED == TRUE)
3892 BTIF_TRACE_DEBUG("%s: rsp_type %d abs_vol %d", __func__, rsp_type, abs_vol);
3895 avrc_rsp.reg_notif.opcode = AVRC_OP_VENDOR;
3896 avrc_rsp.reg_notif.pdu = AVRC_PDU_REGISTER_NOTIFICATION;
3897 avrc_rsp.reg_notif.status = AVRC_STS_NO_ERROR;
3898 avrc_rsp.reg_notif.param.volume = abs_vol;
3899 avrc_rsp.reg_notif.event_id = AVRC_EVT_VOLUME_CHANGE;
3901 status = AVRC_BldResponse(btif_rc_cb.rc_handle, &avrc_rsp, &p_msg);
3902 if (status == AVRC_STS_NO_ERROR) {
3903 BTIF_TRACE_DEBUG("%s msgreq being sent out with label %d",
3905 UINT8* data_start = (UINT8*)(p_msg + 1) + p_msg->offset;
3906 BTA_AvVendorRsp(btif_rc_cb.rc_handle, label,
3907 (rsp_type == BTRC_NOTIFICATION_TYPE_INTERIM) ?
3908 AVRC_RSP_INTERIM : AVRC_RSP_CHANGED,
3909 data_start, p_msg->len, 0);
3910 status = BT_STATUS_SUCCESS;
3912 BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
3918 BTIF_TRACE_DEBUG("%s: feature not enabled", __func__);
3923 /***************************************************************************
3925 ** Function send_groupnavigation_cmd
3927 ** Description Send Pass-Through command
3931 ***************************************************************************/
3932 static bt_status_t send_groupnavigation_cmd(bt_bdaddr_t *bd_addr, uint8_t key_code,
3935 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3936 #if (AVRC_CTLR_INCLUDED == TRUE)
3937 rc_transaction_t *p_transaction=NULL;
3938 BTIF_TRACE_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
3939 key_code, key_state);
3941 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
3943 bt_status_t tran_status = get_transaction(&p_transaction);
3944 if ((BT_STATUS_SUCCESS == tran_status) && (NULL != p_transaction)) {
3945 UINT8 buffer[AVRC_PASS_THRU_GROUP_LEN] = {0};
3946 UINT8* start = buffer;
3947 UINT24_TO_BE_STREAM(start, AVRC_CO_METADATA);
3949 UINT8_TO_BE_STREAM(start, key_code);
3950 BTA_AvRemoteVendorUniqueCmd(btif_rc_cb.rc_handle,
3952 (tBTA_AV_STATE)key_state, buffer,
3953 AVRC_PASS_THRU_GROUP_LEN);
3954 status = BT_STATUS_SUCCESS;
3955 BTIF_TRACE_DEBUG("%s: succesfully sent group_navigation command to BTA",
3960 status = BT_STATUS_FAIL;
3961 BTIF_TRACE_DEBUG("%s: error in fetching transaction", __FUNCTION__);
3966 status = BT_STATUS_FAIL;
3967 BTIF_TRACE_DEBUG("%s: feature not supported", __FUNCTION__);
3970 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
3975 /***************************************************************************
3977 ** Function send_passthrough_cmd
3979 ** Description Send Pass-Through command
3983 ***************************************************************************/
3984 static bt_status_t send_passthrough_cmd(bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state)
3986 tAVRC_STS status = BT_STATUS_UNSUPPORTED;
3987 #if (AVRC_CTLR_INCLUDED == TRUE)
3989 rc_transaction_t *p_transaction=NULL;
3990 BTIF_TRACE_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__,
3991 key_code, key_state);
3992 if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
3994 bt_status_t tran_status = get_transaction(&p_transaction);
3995 if (BT_STATUS_SUCCESS == tran_status && NULL != p_transaction)
3997 BTA_AvRemoteCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
3998 (tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state);
3999 status = BT_STATUS_SUCCESS;
4000 BTIF_TRACE_DEBUG("%s: succesfully sent passthrough command to BTA", __FUNCTION__);
4004 status = BT_STATUS_FAIL;
4005 BTIF_TRACE_DEBUG("%s: error in fetching transaction", __FUNCTION__);
4010 status = BT_STATUS_FAIL;
4011 BTIF_TRACE_DEBUG("%s: feature not supported", __FUNCTION__);
4014 BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
4019 static const btrc_interface_t bt_rc_interface = {
4020 sizeof(bt_rc_interface),
4022 get_play_status_rsp,
4023 NULL, /* list_player_app_attr_rsp */
4024 NULL, /* list_player_app_value_rsp */
4025 NULL, /* get_player_app_value_rsp */
4026 NULL, /* get_player_app_attr_text_rsp */
4027 NULL, /* get_player_app_value_text_rsp */
4028 get_element_attr_rsp,
4029 NULL, /* set_player_app_value_rsp */
4030 register_notification_rsp,
4035 static const btrc_ctrl_interface_t bt_rc_ctrl_interface = {
4036 sizeof(bt_rc_ctrl_interface),
4038 send_passthrough_cmd,
4039 send_groupnavigation_cmd,
4040 change_player_app_setting,
4042 volume_change_notification_rsp,
4046 /*******************************************************************************
4048 ** Function btif_rc_get_interface
4050 ** Description Get the AVRCP Target callback interface
4052 ** Returns btav_interface_t
4054 *******************************************************************************/
4055 const btrc_interface_t *btif_rc_get_interface(void)
4057 BTIF_TRACE_EVENT("%s", __FUNCTION__);
4058 return &bt_rc_interface;
4061 /*******************************************************************************
4063 ** Function btif_rc_ctrl_get_interface
4065 ** Description Get the AVRCP Controller callback interface
4067 ** Returns btav_interface_t
4069 *******************************************************************************/
4070 const btrc_ctrl_interface_t *btif_rc_ctrl_get_interface(void)
4072 BTIF_TRACE_EVENT("%s", __FUNCTION__);
4073 return &bt_rc_ctrl_interface;
4076 /*******************************************************************************
4077 ** Function initialize_transaction
4079 ** Description Initializes fields of the transaction structure
4082 *******************************************************************************/
4083 static void initialize_transaction(int lbl)
4085 pthread_mutex_lock(&device.lbllock);
4086 if (lbl < MAX_TRANSACTIONS_PER_SESSION) {
4087 if (alarm_is_scheduled(device.transaction[lbl].txn_timer)) {
4088 clear_cmd_timeout(lbl);
4090 device.transaction[lbl].lbl = lbl;
4091 device.transaction[lbl].in_use=FALSE;
4092 device.transaction[lbl].handle=0;
4094 pthread_mutex_unlock(&device.lbllock);
4097 /*******************************************************************************
4098 ** Function lbl_init
4100 ** Description Initializes label structures and mutexes.
4103 *******************************************************************************/
4106 memset(&device,0,sizeof(rc_device_t));
4107 pthread_mutexattr_t attr;
4108 pthread_mutexattr_init(&attr);
4109 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
4110 pthread_mutex_init(&(device.lbllock), &attr);
4111 pthread_mutexattr_destroy(&attr);
4112 init_all_transactions();
4115 /*******************************************************************************
4117 ** Function init_all_transactions
4119 ** Description Initializes all transactions
4122 *******************************************************************************/
4123 void init_all_transactions()
4126 for(txn_indx=0; txn_indx < MAX_TRANSACTIONS_PER_SESSION; txn_indx++)
4128 initialize_transaction(txn_indx);
4132 /*******************************************************************************
4134 ** Function get_transaction_by_lbl
4136 ** Description Will return a transaction based on the label. If not inuse
4137 ** will return an error.
4139 ** Returns bt_status_t
4140 *******************************************************************************/
4141 rc_transaction_t *get_transaction_by_lbl(UINT8 lbl)
4143 rc_transaction_t *transaction = NULL;
4144 pthread_mutex_lock(&device.lbllock);
4146 /* Determine if this is a valid label */
4147 if (lbl < MAX_TRANSACTIONS_PER_SESSION)
4149 if (FALSE==device.transaction[lbl].in_use)
4155 transaction = &(device.transaction[lbl]);
4156 BTIF_TRACE_DEBUG("%s: Got transaction.label: %d",__FUNCTION__,lbl);
4160 pthread_mutex_unlock(&device.lbllock);
4164 /*******************************************************************************
4166 ** Function get_transaction
4168 ** Description Obtains the transaction details.
4170 ** Returns bt_status_t
4171 *******************************************************************************/
4173 bt_status_t get_transaction(rc_transaction_t **ptransaction)
4175 bt_status_t result = BT_STATUS_NOMEM;
4177 pthread_mutex_lock(&device.lbllock);
4179 // Check for unused transactions
4180 for (i=0; i<MAX_TRANSACTIONS_PER_SESSION; i++)
4182 if (FALSE==device.transaction[i].in_use)
4184 BTIF_TRACE_DEBUG("%s:Got transaction.label: %d",__FUNCTION__,device.transaction[i].lbl);
4185 device.transaction[i].in_use = TRUE;
4186 *ptransaction = &(device.transaction[i]);
4187 result = BT_STATUS_SUCCESS;
4192 pthread_mutex_unlock(&device.lbllock);
4196 /*******************************************************************************
4198 ** Function release_transaction
4200 ** Description Will release a transaction for reuse
4202 ** Returns bt_status_t
4203 *******************************************************************************/
4204 void release_transaction(UINT8 lbl)
4206 rc_transaction_t *transaction = get_transaction_by_lbl(lbl);
4208 /* If the transaction is in use... */
4209 if (transaction != NULL)
4211 BTIF_TRACE_DEBUG("%s: lbl: %d", __FUNCTION__, lbl);
4212 initialize_transaction(lbl);
4216 /*******************************************************************************
4218 ** Function lbl_destroy
4220 ** Description Cleanup of the mutex
4223 *******************************************************************************/
4226 pthread_mutex_destroy(&(device.lbllock));
4229 /*******************************************************************************
4230 ** Function sleep_ms
4232 ** Description Sleep the calling thread unconditionally for
4233 ** |timeout_ms| milliseconds.
4236 *******************************************************************************/
4237 static void sleep_ms(period_ms_t timeout_ms) {
4238 struct timespec delay;
4239 delay.tv_sec = timeout_ms / 1000;
4240 delay.tv_nsec = 1000 * 1000 * (timeout_ms % 1000);
4242 OSI_NO_INTR(nanosleep(&delay, &delay));
4245 static bool absolute_volume_disabled() {
4246 char volume_disabled[PROPERTY_VALUE_MAX] = {0};
4247 osi_property_get("persist.bluetooth.disableabsvol", volume_disabled, "false");
4248 if (strncmp(volume_disabled, "true", 4) == 0) {
4249 BTIF_TRACE_WARNING("%s: Absolute volume disabled by property", __func__);
4255 static char const* key_id_to_str(uint16_t id) {
4256 for (int i = 0; key_map[i].name != NULL; i++) {
4257 if (id == key_map[i].mapped_id)
4258 return key_map[i].name;
4260 return "UNKNOWN KEY";