diff options
author | Ravi Nagarajan <nravi@broadcom.com> | 2013-03-06 05:29:48 -0800 |
---|---|---|
committer | Zhihai Xu <zhihaixu@google.com> | 2013-03-20 18:56:04 -0700 |
commit | 9adddf4965e9ddb01e339b934c343fcbd842a977 (patch) | |
tree | 303ccd7b4f4ea4f2a13c6263bac5cc5e47c38360 /stack | |
parent | b291d10545c3f316fdcbc21e8f58444c51e72569 (diff) | |
download | android_system_bt-9adddf4965e9ddb01e339b934c343fcbd842a977.tar.gz android_system_bt-9adddf4965e9ddb01e339b934c343fcbd842a977.tar.bz2 android_system_bt-9adddf4965e9ddb01e339b934c343fcbd842a977.zip |
Initial version of Stack for AVRCP 1.3
BTIF and stack changes for supporting AVRCP 1.3
Change-Id: Id02eb7b6a385683cedc41c62b6f829f5d7620bd4
Diffstat (limited to 'stack')
-rwxr-xr-x[-rw-r--r--] | stack/Android.mk | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_api.c | 486 | ||||
-rwxr-xr-x | stack/avrc/avrc_bld_tg.c | 903 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_int.h | 21 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_opt.c | 7 | ||||
-rwxr-xr-x | stack/avrc/avrc_pars_tg.c | 305 | ||||
-rwxr-xr-x[-rw-r--r--] | stack/avrc/avrc_sdp.c | 11 | ||||
-rwxr-xr-x | stack/avrc/avrc_utils.c | 240 |
8 files changed, 1971 insertions, 5 deletions
diff --git a/stack/Android.mk b/stack/Android.mk index e17f4c820..f677ad239 100644..100755 --- a/stack/Android.mk +++ b/stack/Android.mk @@ -45,6 +45,9 @@ LOCAL_SRC_FILES:= \ ./avrc/avrc_api.c \ ./avrc/avrc_sdp.c \ ./avrc/avrc_opt.c \ + ./avrc/avrc_bld_tg.c \ + ./avrc/avrc_pars_tg.c \ + ./avrc/avrc_utils.c \ ./hid/hidh_api.c \ ./hid/hidh_conn.c \ ./bnep/bnep_main.c \ diff --git a/stack/avrc/avrc_api.c b/stack/avrc/avrc_api.c index b6347d751..c2e36d7fb 100644..100755 --- a/stack/avrc/avrc_api.c +++ b/stack/avrc/avrc_api.c @@ -18,7 +18,7 @@ /****************************************************************************** * - * nterface to AVRCP mandatory commands + * Interface to AVRCP mandatory commands * ******************************************************************************/ #include <string.h> @@ -111,6 +111,352 @@ static UINT8 * avrc_get_data_ptr(BT_HDR *p_pkt) return p_data; } +#if (AVRC_METADATA_INCLUDED == TRUE) +/****************************************************************************** +** +** Function avrc_prep_end_frag +** +** Description This function prepares an end response fragment +** +** Returns Nothing. +** +******************************************************************************/ +static void avrc_prep_end_frag(UINT8 handle) +{ + tAVRC_FRAG_CB *p_fcb; + BT_HDR *p_pkt_new; + UINT8 *p_data, *p_orig_data; + UINT8 rsp_type; + + AVRC_TRACE_DEBUG0 ("avrc_prep_end_frag" ); + p_fcb = &avrc_cb.fcb[handle]; + + /* The response type of the end fragment should be the same as the the PDU of "End Fragment + ** Respose" Errata: https://www.bluetooth.org/errata/errata_view.cfm?errata_id=4383 */ + p_orig_data = ((UINT8 *)(p_fcb->p_fmsg + 1) + p_fcb->p_fmsg->offset); + rsp_type = ((*p_orig_data) & AVRC_CTYPE_MASK); + + p_pkt_new = p_fcb->p_fmsg; + p_pkt_new->len -= (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + p_pkt_new->offset += (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + p_data = (UINT8 *)(p_pkt_new+1) + p_pkt_new->offset; + *p_data++ = rsp_type; + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_VENDOR; + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + *p_data++ = p_fcb->frag_pdu; + *p_data++ = AVRC_PKT_END; + /* 4=pdu, pkt_type & len */ + UINT16_TO_BE_STREAM(p_data, (p_pkt_new->len - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE)); +} + +/****************************************************************************** +** +** Function avrc_send_continue_frag +** +** Description This function sends a continue response fragment +** +** Returns Nothing. +** +******************************************************************************/ +static void avrc_send_continue_frag(UINT8 handle, UINT8 label) +{ + tAVRC_FRAG_CB *p_fcb; + BT_HDR *p_pkt_old, *p_pkt; + UINT8 *p_old, *p_data; + UINT8 cr = AVCT_RSP; + tAVRC_RSP rej_rsp; + + p_fcb = &avrc_cb.fcb[handle]; + p_pkt = p_fcb->p_fmsg; + + AVRC_TRACE_DEBUG1 ("avrc_send_continue_frag len(%d) / AVRC_MAX_CTRL_DATA_LEN", p_pkt->len ); + if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) + { + p_pkt_old = p_fcb->p_fmsg; + p_pkt = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + AVCT_MSG_OFFSET + BT_HDR_SIZE)); + if (p_pkt) + { + p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; + p_pkt->offset = AVCT_MSG_OFFSET; + p_pkt->layer_specific = p_pkt_old->layer_specific; + p_pkt->event = p_pkt_old->event; + p_old = (UINT8 *)(p_pkt_old+1) + p_pkt_old->offset; + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + memcpy (p_data, p_old, AVRC_MAX_CTRL_DATA_LEN); + /* use AVRC continue packet type */ + p_data += AVRC_VENDOR_HDR_SIZE; + p_data++; /* pdu */ + *p_data++ = AVRC_PKT_CONTINUE; + /* 4=pdu, pkt_type & len */ + UINT16_TO_BE_STREAM(p_data, (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - 4)); + + /* prepare the left over for as an end fragment */ + avrc_prep_end_frag (handle); + } + else + { + /* use the current GKI buffer to send Internal error status */ + p_pkt = p_fcb->p_fmsg; + p_fcb->p_fmsg = NULL; + p_fcb->frag_enabled = FALSE; + AVRC_TRACE_ERROR0 ("AVRC_MsgReq no buffers for fragmentation - send internal error" ); + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + *p_data++ = AVRC_PDU_REQUEST_CONTINUATION_RSP; + *p_data++ = 0; + UINT16_TO_BE_STREAM(p_data, 0); + p_pkt->len = 4; + rej_rsp.pdu = AVRC_PDU_REQUEST_CONTINUATION_RSP; + rej_rsp.status = AVRC_STS_INTERNAL_ERR; + AVRC_BldResponse( handle, (tAVRC_RESPONSE *)&rej_rsp, &p_pkt); + cr = AVCT_RSP; + } + } + else + { + /* end fragment. clean the control block */ + p_fcb->frag_enabled = FALSE; + p_fcb->p_fmsg = NULL; + } + AVCT_MsgReq( handle, label, cr, p_pkt); +} + +/****************************************************************************** +** +** Function avrc_proc_vendor_command +** +** Description This function processes received vendor command. +** +** Returns if not NULL, the response to send right away. +** +******************************************************************************/ +static BT_HDR * avrc_proc_vendor_command(UINT8 handle, UINT8 label, + BT_HDR *p_pkt, tAVRC_MSG_VENDOR *p_msg) +{ + BT_HDR *p_rsp = NULL; + UINT8 *p_data; + UINT8 *p_begin; + UINT8 pkt_type; + BOOLEAN abort_frag = FALSE; + tAVRC_STS status = AVRC_STS_NO_ERROR; + tAVRC_FRAG_CB *p_fcb; + + p_begin = (UINT8 *)(p_pkt+1) + p_pkt->offset; + p_data = p_begin + AVRC_VENDOR_HDR_SIZE; + pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; + + if (pkt_type != AVRC_PKT_SINGLE) + { + /* reject - commands can only be in single packets at AVRCP level */ + AVRC_TRACE_ERROR1 ("commands must be in single packet pdu:0x%x", *p_data ); + /* use the current GKI buffer to send the reject */ + status = AVRC_STS_BAD_CMD; + } + /* check if there are fragments waiting to be sent */ + else if (avrc_cb.fcb[handle].frag_enabled) + { + p_fcb = &avrc_cb.fcb[handle]; + if (p_msg->company_id == AVRC_CO_METADATA) + { + switch (*p_data) + { + case AVRC_PDU_ABORT_CONTINUATION_RSP: + /* aborted by CT - send accept response */ + abort_frag = TRUE; + p_begin = (UINT8 *)(p_pkt+1) + p_pkt->offset; + *p_begin = (AVRC_RSP_ACCEPT & AVRC_CTYPE_MASK); + if (*(p_data + 4) != p_fcb->frag_pdu) + { + *p_begin = (AVRC_RSP_REJ & AVRC_CTYPE_MASK); + *(p_data + 4) = AVRC_STS_BAD_PARAM; + } + else + { + p_data = (p_begin + AVRC_VENDOR_HDR_SIZE + 2); + UINT16_TO_BE_STREAM(p_data, 0); + p_pkt->len = (p_data - p_begin); + } + AVCT_MsgReq( handle, label, AVCT_RSP, p_pkt); + p_msg->hdr.opcode = AVRC_OP_DROP; /* used the p_pkt to send response */ + break; + + case AVRC_PDU_REQUEST_CONTINUATION_RSP: + if (*(p_data + 4) == p_fcb->frag_pdu) + { + avrc_send_continue_frag(handle, label); + p_msg->hdr.opcode = AVRC_OP_DROP_N_FREE; + } + else + { + /* the pdu id does not match - reject the command using the current GKI buffer */ + AVRC_TRACE_ERROR2("avrc_proc_vendor_command continue pdu: 0x%x does not match \ + current re-assembly pdu: 0x%x", + *(p_data + 4), p_fcb->frag_pdu); + status = AVRC_STS_BAD_PARAM; + abort_frag = TRUE; + } + break; + + default: + /* implicit abort */ + abort_frag = TRUE; + } + } + else + { + abort_frag = TRUE; + /* implicit abort */ + } + + if (abort_frag) + { + if (p_fcb->p_fmsg) + GKI_freebuf(p_fcb->p_fmsg); + p_fcb->p_fmsg = NULL; + p_fcb->frag_enabled = FALSE; + } + } + + if (status != AVRC_STS_NO_ERROR) + { + /* use the current GKI buffer to build/send the reject message */ + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + *p_data++ = AVRC_RSP_REJ; + p_data += AVRC_VENDOR_HDR_SIZE; /* pdu */ + *p_data++ = 0; /* pkt_type */ + UINT16_TO_BE_STREAM(p_data, 1); /* len */ + *p_data++ = status; /* error code */ + p_pkt->len = AVRC_VENDOR_HDR_SIZE + 5; + p_rsp = p_pkt; + } + + return p_rsp; +} + +/****************************************************************************** +** +** Function avrc_proc_far_msg +** +** Description This function processes vendor command/response fragmetation +** and reassembly +** +** Returns 0, to report the message with msg_cback . +** +******************************************************************************/ +static UINT8 avrc_proc_far_msg(UINT8 handle, UINT8 label, UINT8 cr, BT_HDR **pp_pkt, + tAVRC_MSG_VENDOR *p_msg) +{ + BT_HDR *p_pkt = *pp_pkt; + UINT8 *p_data; + BOOLEAN drop = FALSE; + BT_HDR *p_rsp = NULL; + BT_HDR *p_cmd = NULL; + BOOLEAN req_continue = FALSE; + BT_HDR *p_pkt_new = NULL; + UINT8 pkt_type; + UINT16 buf_len; + tAVRC_RASM_CB *p_rcb; + tAVRC_NEXT_CMD avrc_cmd; + + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + pkt_type = *(p_data + 1) & AVRC_PKT_TYPE_MASK; + AVRC_TRACE_DEBUG1 ("pkt_type %d", pkt_type ); + p_rcb = &avrc_cb.rcb[handle]; + if (p_msg->company_id == AVRC_CO_METADATA) + { + /* check if the message needs to be re-assembled */ + if (pkt_type == AVRC_PKT_SINGLE || pkt_type == AVRC_PKT_START) + { + /* previous fragments need to be dropped, when received another new message */ + p_rcb->rasm_offset = 0; + if (p_rcb->p_rmsg) + { + GKI_freebuf(p_rcb->p_rmsg); + p_rcb->p_rmsg = NULL; + } + } + + if (pkt_type != AVRC_PKT_SINGLE && cr == AVCT_RSP) + { + /* not a single response packet - need to re-assemble metadata messages */ + if (pkt_type == AVRC_PKT_START) + { + p_rcb->rasm_offset = p_pkt->offset; + p_rcb->p_rmsg = p_pkt; + /* set offset to point to where to copy next - use the same re-asm logic as AVCT */ + p_rcb->p_rmsg->offset += p_rcb->p_rmsg->len; + p_rcb->rasm_pdu = *p_data; + req_continue = TRUE; + } + else + { + /* get size of buffer holding assembled message */ + buf_len = GKI_get_buf_size (p_rcb->p_rmsg) - sizeof(BT_HDR); + /* adjust offset and len of fragment for header byte */ + p_pkt->offset += (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); + p_pkt->len -= (AVRC_VENDOR_HDR_SIZE + AVRC_MIN_META_HDR_SIZE); + /* verify length */ + if ((p_rcb->p_rmsg->offset + p_pkt->len) > buf_len) + { + AVRC_TRACE_WARNING0("Fragmented message too big! - report the partial message"); + p_pkt->len = buf_len - p_rcb->p_rmsg->offset; + pkt_type = AVRC_PKT_END; + } + + /* copy contents of p_pkt to p_rx_msg */ + memcpy((UINT8 *)(p_rcb->p_rmsg + 1) + p_rcb->p_rmsg->offset, + (UINT8 *)(p_pkt + 1) + p_pkt->offset, p_pkt->len); + + if (pkt_type == AVRC_PKT_END) + { + p_rcb->p_rmsg->offset = p_rcb->rasm_offset; + p_rcb->p_rmsg->len += p_pkt->len; + p_pkt_new = p_rcb->p_rmsg; + p_rcb->rasm_offset = 0; + p_rcb->p_rmsg = NULL; + p_msg->p_vendor_data = (UINT8 *)(p_pkt_new+1) + p_pkt_new->offset; + p_msg->hdr.ctype = p_msg->p_vendor_data[0] & AVRC_CTYPE_MASK; + /* 6 = ctype, subunit*, opcode & CO_ID */ + p_msg->p_vendor_data += AVRC_VENDOR_HDR_SIZE; + p_msg->vendor_len = p_pkt_new->len - AVRC_VENDOR_HDR_SIZE; + p_data = p_msg->p_vendor_data + 1; /* skip pdu */ + *p_data++ = AVRC_PKT_SINGLE; + UINT16_TO_BE_STREAM(p_data, (p_msg->vendor_len - AVRC_MIN_META_HDR_SIZE)); + AVRC_TRACE_DEBUG3("end frag:%d, total len:%d, offset:%d", p_pkt->len, + p_pkt_new->len, p_pkt_new->offset); + } + else + { + p_rcb->p_rmsg->offset += p_pkt->len; + p_rcb->p_rmsg->len += p_pkt->len; + p_pkt_new = NULL; + req_continue = TRUE; + } + GKI_freebuf(p_pkt); + *pp_pkt = p_pkt_new; + } + } + + if (cr == AVCT_CMD) + { + p_rsp = avrc_proc_vendor_command(handle, label, *pp_pkt, p_msg); + if (p_rsp) + { + AVCT_MsgReq( handle, label, AVCT_RSP, p_rsp); + drop = 3; + } + else if (p_msg->hdr.opcode == AVRC_OP_DROP) + { + drop = 1; + } + else if (p_msg->hdr.opcode == AVRC_OP_DROP_N_FREE) + drop = 4; + + } + } + return drop; +} +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ /****************************************************************************** ** @@ -184,7 +530,8 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, p_rsp = p_pkt; /* this also sets free = FALSE, drop = TRUE */ /* check & set the offset. set response code, set subunit_type & subunit_id, set AVRC_OP_UNIT_INFO */ - p_rsp_data = avrc_get_data_ptr(p_pkt) + AVRC_AVC_HDR_SIZE; /* 3 bytes: ctype, subunit*, opcode */ + /* 3 bytes: ctype, subunit*, opcode */ + p_rsp_data = avrc_get_data_ptr(p_pkt) + AVRC_AVC_HDR_SIZE; *p_rsp_data++ = 7; /* Panel subunit & id=0 */ *p_rsp_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); @@ -256,6 +603,34 @@ static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr, p_msg->p_vendor_data = p_data; p_msg->vendor_len = p_pkt->len - (p_data - p_begin); +#if (AVRC_METADATA_INCLUDED == TRUE) + drop = avrc_proc_far_msg(handle, label, cr, &p_pkt, p_msg); + if (drop) + { + free = FALSE; + if (drop == 4) + free = TRUE; +#if (BT_USE_TRACES == TRUE) + switch (drop) + { + case 1: + p_drop_msg = "sent_frag"; + break; + case 2: + p_drop_msg = "req_cont"; + break; + case 3: + p_drop_msg = "sent_frag3"; + break; + case 4: + p_drop_msg = "sent_frag_free"; + break; + default: + p_drop_msg = "sent_fragd"; + } +#endif + } +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ break; case AVRC_OP_PASS_THRU: @@ -458,8 +833,13 @@ UINT16 AVRC_Open(UINT8 *p_handle, tAVRC_CONN_CB *p_ccb, BD_ADDR_PTR peer_addr) if (status == AVCT_SUCCESS) { memcpy(&avrc_cb.ccb[*p_handle], p_ccb, sizeof(tAVRC_CONN_CB)); +#if (AVRC_METADATA_INCLUDED == TRUE) + memset(&avrc_cb.fcb[*p_handle], 0, sizeof(tAVRC_FRAG_CB)); + memset(&avrc_cb.rcb[*p_handle], 0, sizeof(tAVRC_RASM_CB)); +#endif } - AVRC_TRACE_DEBUG4("AVRC_Open role: %d, control:%d status:%d, handle:%d", cc.role, cc.control, status, *p_handle); + AVRC_TRACE_DEBUG4("AVRC_Open role: %d, control:%d status:%d, handle:%d", cc.role, cc.control, + status, *p_handle); return status; } @@ -507,8 +887,108 @@ UINT16 AVRC_Close(UINT8 handle) ******************************************************************************/ UINT16 AVRC_MsgReq (UINT8 handle, UINT8 label, UINT8 ctype, BT_HDR *p_pkt) { +#if (AVRC_METADATA_INCLUDED == TRUE) + UINT8 *p_data; + UINT8 cr = AVCT_CMD; + BOOLEAN chk_frag = TRUE; + UINT8 *p_start = NULL; + tAVRC_FRAG_CB *p_fcb; + UINT16 len; + BT_HDR *p_pkt_new; + + if (!p_pkt) + return AVRC_BAD_PARAM; + + if (ctype >= AVRC_RSP_NOT_IMPL) + cr = AVCT_RSP; + + if (p_pkt->event == AVRC_OP_VENDOR) + { + /* add AVRCP Vendor Dependent headers */ + p_start = ((UINT8 *)(p_pkt + 1) + p_pkt->offset); + p_pkt->offset -= AVRC_VENDOR_HDR_SIZE; + p_pkt->len += AVRC_VENDOR_HDR_SIZE; + p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + *p_data++ = (ctype & AVRC_CTYPE_MASK); + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_VENDOR; + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + } + else if (p_pkt->event == AVRC_OP_PASS_THRU) + { + /* add AVRCP Pass Through headers */ + p_start = ((UINT8 *)(p_pkt + 1) + p_pkt->offset); + p_pkt->offset -= AVRC_PASS_THRU_SIZE; + p_pkt->len += AVRC_PASS_THRU_SIZE; + p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + *p_data++ = (ctype & AVRC_CTYPE_MASK); + *p_data++ = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT); + *p_data++ = AVRC_OP_PASS_THRU;/* opcode */ + *p_data++ = AVRC_ID_VENDOR; /* operation id */ + *p_data++ = 5; /* operation data len */ + AVRC_CO_ID_TO_BE_STREAM(p_data, AVRC_CO_METADATA); + } + + /* abandon previous fragments */ + p_fcb = &avrc_cb.fcb[handle]; + if (p_fcb->frag_enabled) + p_fcb->frag_enabled = FALSE; + + if (p_fcb->p_fmsg) + { + GKI_freebuf(p_fcb->p_fmsg); + p_fcb->p_fmsg = NULL; + } + + /* AVRCP spec has not defined any control channel commands that needs fragmentation at this level + * check for fragmentation only on the response */ + if ((cr == AVCT_RSP) && (chk_frag == TRUE)) + { + if (p_pkt->len > AVRC_MAX_CTRL_DATA_LEN) + { + AVRC_TRACE_DEBUG1 ("p_pkt->len(%d) > AVRC_MAX_CTRL_DATA_LEN", p_pkt->len ); + p_pkt_new = (BT_HDR *)GKI_getbuf((UINT16)(AVRC_PACKET_LEN + AVCT_MSG_OFFSET + + BT_HDR_SIZE)); + if (p_pkt_new) + { + p_fcb->frag_enabled = TRUE; + p_fcb->p_fmsg = p_pkt; + p_fcb->frag_pdu = *p_start; + p_pkt = p_pkt_new; + p_pkt_new = p_fcb->p_fmsg; + p_pkt->len = AVRC_MAX_CTRL_DATA_LEN; + p_pkt->offset = p_pkt_new->offset; + p_pkt->layer_specific = p_pkt_new->layer_specific; + p_pkt->event = p_pkt_new->event; + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + p_start -= AVRC_VENDOR_HDR_SIZE; + memcpy (p_data, p_start, AVRC_MAX_CTRL_DATA_LEN); + /* use AVRC start packet type */ + p_data += AVRC_VENDOR_HDR_SIZE; + p_data++; /* pdu */ + *p_data++ = AVRC_PKT_START; + /* 4 pdu, pkt_type & len */ + len = (AVRC_MAX_CTRL_DATA_LEN - AVRC_VENDOR_HDR_SIZE - AVRC_MIN_META_HDR_SIZE); + UINT16_TO_BE_STREAM(p_data, len); + + /* prepare the left over for as an end fragment */ + avrc_prep_end_frag (handle); + AVRC_TRACE_DEBUG3 ("p_pkt len:%d/%d, next len:%d", p_pkt->len, len, p_fcb->p_fmsg->len ); + } + else + { + AVRC_TRACE_ERROR0 ("AVRC_MsgReq no buffers for fragmentation" ); + GKI_freebuf(p_pkt); return AVRC_NO_RESOURCES; } + } + } + + return AVCT_MsgReq( handle, label, cr, p_pkt); +#else + return AVRC_NO_RESOURCES; +#endif +} /****************************************************************************** diff --git a/stack/avrc/avrc_bld_tg.c b/stack/avrc/avrc_bld_tg.c new file mode 100755 index 000000000..d201b9dc2 --- /dev/null +++ b/stack/avrc/avrc_bld_tg.c @@ -0,0 +1,903 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2013 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ +#include <string.h> + +#include "gki.h" +#include "avrc_api.h" +#include "avrc_defs.h" +#include "avrc_int.h" + +/***************************************************************************** +** Global data +*****************************************************************************/ +#if (AVRC_METADATA_INCLUDED == TRUE) + +/******************************************************************************* +** +** Function avrc_bld_get_capability_rsp +** +** Description This function builds the Get Capability response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_capability_rsp (tAVRC_GET_CAPS_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len = 0; + UINT8 xx; + UINT32 *p_company_id; + UINT8 *p_event_id; + tAVRC_STS status = AVRC_STS_NO_ERROR; + + if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id))) + { + AVRC_TRACE_ERROR1("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", p_rsp); + status = AVRC_STS_BAD_PARAM; + return status; + } + + AVRC_TRACE_API0("avrc_bld_get_capability_rsp"); + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + UINT8_TO_BE_STREAM(p_data, p_rsp->capability_id); + p_count = p_data; + + if (len == 0) + { + *p_count = p_rsp->count; + p_data++; + len = 2; /* move past the capability_id and count */ + } + else + { + p_data = p_start + p_pkt->len; + *p_count += p_rsp->count; + } + + if (p_rsp->capability_id == AVRC_CAP_COMPANY_ID) + { + p_company_id = p_rsp->param.company_id; + for (xx=0; xx< p_rsp->count; xx++) + { + UINT24_TO_BE_STREAM(p_data, p_company_id[xx]); + } + len += p_rsp->count * 3; + } + else + { + p_event_id = p_rsp->param.event_id; + *p_count = 0; + for (xx=0; xx< p_rsp->count; xx++) + { + if (AVRC_IS_VALID_EVENT_ID(p_event_id[xx])) + { + (*p_count)++; + UINT8_TO_BE_STREAM(p_data, p_event_id[xx]); + } + } + len += (*p_count); + } + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + status = AVRC_STS_NO_ERROR; + + return status; +} + +/******************************************************************************* +** +** Function avrc_bld_list_app_settings_attr_rsp +** +** Description This function builds the List Application Settings Attribute +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_list_app_settings_attr_rsp (tAVRC_LIST_APP_ATTR_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_num; + UINT16 len = 0; + UINT8 xx; + + AVRC_TRACE_API0("avrc_bld_list_app_settings_attr_rsp"); + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_num = p_data; + if (len == 0) + { + /* first time initialize the attribute count */ + *p_num = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_attr; xx++) + { + if(AVRC_IsValidPlayerAttr(p_rsp->attrs[xx])) + { + (*p_num)++; + UINT8_TO_BE_STREAM(p_data, p_rsp->attrs[xx]); + } + } + + len = *p_num + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_list_app_settings_values_rsp +** +** Description This function builds the List Application Setting Values +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_list_app_settings_values_rsp (tAVRC_LIST_APP_VALUES_RSP *p_rsp, + BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_num; + UINT8 xx; + UINT16 len; + + AVRC_TRACE_API0("avrc_bld_list_app_settings_values_rsp"); + + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + /* get the existing length, if any, and also the num attributes */ + BE_STREAM_TO_UINT16(len, p_data); + p_num = p_data; + /* first time initialize the attribute count */ + if (len == 0) + { + *p_num = p_rsp->num_val; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + *p_num += p_rsp->num_val; + } + + + for (xx=0; xx<p_rsp->num_val; xx++) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->vals[xx]); + } + + len = *p_num + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_get_cur_app_setting_value_rsp +** +** Description This function builds the Get Current Application Setting Value +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_cur_app_setting_value_rsp (tAVRC_GET_CUR_APP_VALUE_RSP *p_rsp, + BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len; + UINT8 xx; + + if (!p_rsp->p_vals) + { + AVRC_TRACE_ERROR0("avrc_bld_get_cur_app_setting_value_rsp NULL parameter"); + return AVRC_STS_BAD_PARAM; + } + + AVRC_TRACE_API0("avrc_bld_get_cur_app_setting_value_rsp"); + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + if (len == 0) + { + /* first time initialize the attribute count */ + *p_count = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_val; xx++) + { + if (avrc_is_valid_player_attrib_value(p_rsp->p_vals[xx].attr_id, p_rsp->p_vals[xx].attr_val)) + { + (*p_count)++; + UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_id); + UINT8_TO_BE_STREAM(p_data, p_rsp->p_vals[xx].attr_val); + } + } + len = ((*p_count) << 1) + 1; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_set_app_setting_value_rsp +** +** Description This function builds the Set Application Setting Value +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_set_app_setting_value_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_set_app_setting_value_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_app_setting_text_rsp +** +** Description This function builds the Get Application Settings Attribute Text +** or Get Application Settings Value Text response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len, len_left; + UINT8 xx; + tAVRC_STS sts = AVRC_STS_NO_ERROR; + UINT8 num_added = 0; + + if (!p_rsp->p_attrs) + { + AVRC_TRACE_ERROR0("avrc_bld_app_setting_text_rsp NULL parameter"); + return AVRC_STS_BAD_PARAM; + } + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + len_left = GKI_get_buf_size(p_pkt) - BT_HDR_SIZE - p_pkt->offset - p_pkt->len; + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + + if (len == 0) + { + *p_count = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_attr; xx++) + { + if (len_left < (p_rsp->p_attrs[xx].str_len + 4)) + { + AVRC_TRACE_ERROR3("avrc_bld_app_setting_text_rsp out of room (str_len:%d, left:%d)", + xx, p_rsp->p_attrs[xx].str_len, len_left); + p_rsp->num_attr = num_added; + sts = AVRC_STS_INTERNAL_ERR; + break; + } + if ( !p_rsp->p_attrs[xx].str_len || !p_rsp->p_attrs[xx].p_str ) + { + AVRC_TRACE_ERROR1("avrc_bld_app_setting_text_rsp NULL attr text[%d]", xx); + continue; + } + UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].charset_id); + UINT8_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].str_len); + ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].p_str, p_rsp->p_attrs[xx].str_len); + (*p_count)++; + num_added++; + } + len = p_data - p_count; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return sts; +} + +/******************************************************************************* +** +** Function avrc_bld_get_app_setting_attr_text_rsp +** +** Description This function builds the Get Application Setting Attribute Text +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_app_setting_attr_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, + BT_HDR *p_pkt) +{ + AVRC_TRACE_API0("avrc_bld_get_app_setting_attr_text_rsp"); + return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); +} + +/******************************************************************************* +** +** Function avrc_bld_get_app_setting_value_text_rsp +** +** Description This function builds the Get Application Setting Value Text +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_app_setting_value_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp, + BT_HDR *p_pkt) +{ + AVRC_TRACE_API0("avrc_bld_get_app_setting_value_text_rsp"); + return avrc_bld_app_setting_text_rsp(p_rsp, p_pkt); +} + +/******************************************************************************* +** +** Function avrc_bld_inform_charset_rsp +** +** Description This function builds the Inform Displayable Character Set +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_inform_charset_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_inform_charset_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_inform_battery_status_rsp +** +** Description This function builds the Inform Battery Status +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_inform_battery_status_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_inform_battery_status_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_get_elem_attrs_rsp +** +** Description This function builds the Get Element Attributes +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_elem_attrs_rsp (tAVRC_GET_ELEM_ATTRS_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start, *p_len, *p_count; + UINT16 len; + UINT8 xx; + + AVRC_TRACE_API0("avrc_bld_get_elem_attrs_rsp"); + if (!p_rsp->p_attrs) + { + AVRC_TRACE_ERROR0("avrc_bld_get_elem_attrs_rsp NULL parameter"); + return AVRC_STS_BAD_PARAM; + } + + /* get the existing length, if any, and also the num attributes */ + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + + BE_STREAM_TO_UINT16(len, p_data); + p_count = p_data; + + if (len == 0) + { + *p_count = 0; + p_data++; + } + else + { + p_data = p_start + p_pkt->len; + } + + for (xx=0; xx<p_rsp->num_attr; xx++) + { + if (!AVRC_IS_VALID_MEDIA_ATTRIBUTE(p_rsp->p_attrs[xx].attr_id)) + { + AVRC_TRACE_ERROR2("avrc_bld_get_elem_attrs_rsp invalid attr id[%d]: %d", xx, p_rsp->p_attrs[xx].attr_id); + continue; + } + if ( !p_rsp->p_attrs[xx].name.p_str ) + { + p_rsp->p_attrs[xx].name.str_len = 0; + } + UINT32_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].attr_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.charset_id); + UINT16_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.str_len); + ARRAY_TO_BE_STREAM(p_data, p_rsp->p_attrs[xx].name.p_str, p_rsp->p_attrs[xx].name.str_len); + (*p_count)++; + } + len = p_data - p_count; + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_get_play_status_rsp +** +** Description This function builds the Get Play Status +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_get_play_status_rsp (tAVRC_GET_PLAY_STATUS_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start; + + AVRC_TRACE_API0("avrc_bld_get_play_status_rsp"); + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; + + /* add fixed lenth - song len(4) + song position(4) + status(1) */ + UINT16_TO_BE_STREAM(p_data, 9); + UINT32_TO_BE_STREAM(p_data, p_rsp->song_len); + UINT32_TO_BE_STREAM(p_data, p_rsp->song_pos); + UINT8_TO_BE_STREAM(p_data, p_rsp->play_status); + p_pkt->len = (p_data - p_start); + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_notify_rsp +** +** Description This function builds the Notification response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_notify_rsp (tAVRC_REG_NOTIF_RSP *p_rsp, BT_HDR *p_pkt) +{ + UINT8 *p_data, *p_start; + UINT8 *p_len; + UINT16 len = 0; + UINT8 xx; + tAVRC_STS status = AVRC_STS_NO_ERROR; + + AVRC_TRACE_API0("avrc_bld_notify_rsp"); + + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_len = p_start + 2; /* pdu + rsvd */ + p_data += 2; + + UINT8_TO_BE_STREAM(p_data, p_rsp->event_id); + switch (p_rsp->event_id) + { + case AVRC_EVT_PLAY_STATUS_CHANGE: /* 0x01 */ + /* p_rsp->param.play_status >= AVRC_PLAYSTATE_STOPPED is always TRUE */ + if ((p_rsp->param.play_status <= AVRC_PLAYSTATE_REV_SEEK) || + (p_rsp->param.play_status == AVRC_PLAYSTATE_ERROR) ) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.play_status); + len = 2; + } + else + { + AVRC_TRACE_ERROR0("bad play state"); + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_EVT_TRACK_CHANGE: /* 0x02 */ + ARRAY_TO_BE_STREAM(p_data, p_rsp->param.track, AVRC_UID_SIZE); + len = (UINT8)(AVRC_UID_SIZE + 1); + break; + + case AVRC_EVT_TRACK_REACHED_END: /* 0x03 */ + case AVRC_EVT_TRACK_REACHED_START: /* 0x04 */ + len = 1; + break; + + case AVRC_EVT_PLAY_POS_CHANGED: /* 0x05 */ + UINT32_TO_BE_STREAM(p_data, p_rsp->param.play_pos); + len = 5; + break; + + case AVRC_EVT_BATTERY_STATUS_CHANGE: /* 0x06 */ + if (AVRC_IS_VALID_BATTERY_STATUS(p_rsp->param.battery_status)) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.battery_status); + len = 2; + } + else + { + AVRC_TRACE_ERROR0("bad battery status"); + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_EVT_SYSTEM_STATUS_CHANGE: /* 0x07 */ + if (AVRC_IS_VALID_SYSTEM_STATUS(p_rsp->param.system_status)) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.system_status); + len = 2; + } + else + { + AVRC_TRACE_ERROR0("bad system status"); + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_EVT_APP_SETTING_CHANGE: /* 0x08 */ + if (p_rsp->param.player_setting.num_attr > AVRC_MAX_APP_SETTINGS) + p_rsp->param.player_setting.num_attr = AVRC_MAX_APP_SETTINGS; + + if (p_rsp->param.player_setting.num_attr > 0) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.num_attr); + len = 2; + for (xx=0; xx<p_rsp->param.player_setting.num_attr; xx++) + { + if (avrc_is_valid_player_attrib_value(p_rsp->param.player_setting.attr_id[xx], + p_rsp->param.player_setting.attr_value[xx])) + { + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_id[xx]); + UINT8_TO_BE_STREAM(p_data, p_rsp->param.player_setting.attr_value[xx]); + } + else + { + AVRC_TRACE_ERROR0("bad player app seeting attribute or value"); + status = AVRC_STS_BAD_PARAM; + break; + } + len += 2; + } + } + else + status = AVRC_STS_BAD_PARAM; + break; + + default: + status = AVRC_STS_BAD_PARAM; + AVRC_TRACE_ERROR0("unknown event_id"); + } + + UINT16_TO_BE_STREAM(p_len, len); + p_pkt->len = (p_data - p_start); + + return status; +} + +/******************************************************************************* +** +** Function avrc_bld_next_rsp +** +** Description This function builds the Request Continue or Abort +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_next_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt) +{ + /* nothing to be added. */ + AVRC_TRACE_API0("avrc_bld_next_rsp"); + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_group_navigation_rsp +** +** Description This function builds the Group Navigation +** response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +tAVRC_STS avrc_bld_group_navigation_rsp (UINT16 navi_id, BT_HDR *p_pkt) +{ + UINT8 *p_data; + + if (!AVRC_IS_VALID_GROUP(navi_id)) + { + AVRC_TRACE_ERROR1("avrc_bld_group_navigation_rsp bad navigation op id: %d", navi_id); + return AVRC_STS_BAD_PARAM; + } + + AVRC_TRACE_API0("avrc_bld_group_navigation_rsp"); + p_data = (UINT8 *)(p_pkt+1) + p_pkt->offset; + UINT16_TO_BE_STREAM(p_data, navi_id); + p_pkt->len = 2; + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_rejected_rsp +** +** Description This function builds the General Response response. +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +static tAVRC_STS avrc_bld_rejected_rsp( tAVRC_RSP *p_rsp, BT_HDR *p_pkt ) +{ + UINT8 *p_data, *p_start; + + AVRC_TRACE_API2("avrc_bld_rejected_rsp: status=%d, pdu:x%x", p_rsp->status, p_rsp->pdu); + + p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_data = p_start + 2; + AVRC_TRACE_DEBUG1("pdu:x%x", *p_start); + + UINT16_TO_BE_STREAM(p_data, 1); + UINT8_TO_BE_STREAM(p_data, p_rsp->status); + p_pkt->len = p_data - p_start; + + return AVRC_STS_NO_ERROR; +} + +/******************************************************************************* +** +** Function avrc_bld_init_rsp_buffer +** +** Description This function initializes the response buffer based on PDU +** +** Returns NULL, if no GKI buffer or failure to build the message. +** Otherwise, the GKI buffer that contains the initialized message. +** +*******************************************************************************/ +static BT_HDR *avrc_bld_init_rsp_buffer(tAVRC_RESPONSE *p_rsp) +{ + UINT16 offset = AVRC_MSG_PASS_THRU_OFFSET, chnl = AVCT_DATA_CTRL, len=AVRC_META_CMD_POOL_SIZE; + BT_HDR *p_pkt=NULL; + UINT8 opcode = avrc_opcode_from_pdu(p_rsp->pdu); + + AVRC_TRACE_API3("avrc_bld_init_rsp_buffer: pdu=%x, opcode=%x/%x", p_rsp->pdu, opcode, + p_rsp->rsp.opcode); + if (opcode != p_rsp->rsp.opcode && p_rsp->rsp.status != AVRC_STS_NO_ERROR && + avrc_is_valid_opcode(p_rsp->rsp.opcode)) + { + opcode = p_rsp->rsp.opcode; + AVRC_TRACE_API1("opcode=%x", opcode); + } + + switch (opcode) + { + case AVRC_OP_PASS_THRU: + offset = AVRC_MSG_PASS_THRU_OFFSET; + break; + + case AVRC_OP_VENDOR: + offset = AVRC_MSG_VENDOR_OFFSET; + if (p_rsp->pdu == AVRC_PDU_GET_ELEMENT_ATTR) + len = AVRC_BROWSE_POOL_SIZE; + break; + } + + /* allocate and initialize the buffer */ + p_pkt = (BT_HDR *)GKI_getbuf(len); + if (p_pkt) + { + UINT8 *p_data, *p_start; + + p_pkt->layer_specific = chnl; + p_pkt->event = opcode; + p_pkt->offset = offset; + p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset; + p_start = p_data; + + /* pass thru - group navigation - has a two byte op_id, so dont do it here */ + if (opcode != AVRC_OP_PASS_THRU) + *p_data++ = p_rsp->pdu; + + switch (opcode) + { + case AVRC_OP_VENDOR: + /* reserved 0, packet_type 0 */ + UINT8_TO_BE_STREAM(p_data, 0); + /* continue to the next "case to add length */ + /* add fixed lenth - 0 */ + UINT16_TO_BE_STREAM(p_data, 0); + break; + } + + p_pkt->len = (p_data - p_start); + } + p_rsp->rsp.opcode = opcode; + return p_pkt; +} + +/******************************************************************************* +** +** Function AVRC_BldResponse +** +** Description This function builds the given AVRCP response to the given +** GKI buffer +** +** Returns AVRC_STS_NO_ERROR, if the response is built successfully +** Otherwise, the error code. +** +*******************************************************************************/ +tAVRC_STS AVRC_BldResponse( UINT8 handle, tAVRC_RESPONSE *p_rsp, BT_HDR **pp_pkt) +{ + tAVRC_STS status = AVRC_STS_BAD_PARAM; + BT_HDR *p_pkt; + BOOLEAN alloc = FALSE; + + if (!p_rsp || !pp_pkt) + { + AVRC_TRACE_API2("AVRC_BldResponse. Invalid parameters passed. p_rsp=%p, pp_pkt=%p", + p_rsp, pp_pkt); + return AVRC_STS_BAD_PARAM; + } + + if (*pp_pkt == NULL) + { + if ((*pp_pkt = avrc_bld_init_rsp_buffer(p_rsp)) == NULL) + { + AVRC_TRACE_API0("AVRC_BldResponse: Failed to initialize response buffer"); + return AVRC_STS_INTERNAL_ERR; + } + alloc = TRUE; + } + status = AVRC_STS_NO_ERROR; + p_pkt = *pp_pkt; + + AVRC_TRACE_API2("AVRC_BldResponse: pdu=%x status=%x", p_rsp->rsp.pdu, p_rsp->rsp.status); + if (p_rsp->rsp.status != AVRC_STS_NO_ERROR) + { + return( avrc_bld_rejected_rsp(&p_rsp->rsp, p_pkt) ); + } + + switch (p_rsp->pdu) + { + case AVRC_PDU_NEXT_GROUP: + case AVRC_PDU_PREV_GROUP: + status = avrc_bld_group_navigation_rsp(p_rsp->pdu, p_pkt); + break; + + case AVRC_PDU_GET_CAPABILITIES: + status = avrc_bld_get_capability_rsp(&p_rsp->get_caps, p_pkt); + break; + + case AVRC_PDU_LIST_PLAYER_APP_ATTR: + status = avrc_bld_list_app_settings_attr_rsp(&p_rsp->list_app_attr, p_pkt); + break; + + case AVRC_PDU_LIST_PLAYER_APP_VALUES: + status = avrc_bld_list_app_settings_values_rsp(&p_rsp->list_app_values, p_pkt); + break; + + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: + status = avrc_bld_get_cur_app_setting_value_rsp(&p_rsp->get_cur_app_val, p_pkt); + break; + + case AVRC_PDU_SET_PLAYER_APP_VALUE: + status = avrc_bld_set_app_setting_value_rsp(&p_rsp->set_app_val, p_pkt); + break; + + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: + status = avrc_bld_get_app_setting_attr_text_rsp(&p_rsp->get_app_attr_txt, p_pkt); + break; + + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: + status = avrc_bld_get_app_setting_value_text_rsp(&p_rsp->get_app_val_txt, p_pkt); + break; + + case AVRC_PDU_INFORM_DISPLAY_CHARSET: + status = avrc_bld_inform_charset_rsp(&p_rsp->inform_charset, p_pkt); + break; + + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: + status = avrc_bld_inform_battery_status_rsp(&p_rsp->inform_battery_status, p_pkt); + break; + + case AVRC_PDU_GET_ELEMENT_ATTR: + status = avrc_bld_get_elem_attrs_rsp(&p_rsp->get_elem_attrs, p_pkt); + break; + + case AVRC_PDU_GET_PLAY_STATUS: + status = avrc_bld_get_play_status_rsp(&p_rsp->get_play_status, p_pkt); + break; + + case AVRC_PDU_REGISTER_NOTIFICATION: + status = avrc_bld_notify_rsp(&p_rsp->reg_notif, p_pkt); + break; + + case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ + status = avrc_bld_next_rsp(&p_rsp->continu, p_pkt); + break; + + case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ + status = avrc_bld_next_rsp(&p_rsp->abort, p_pkt); + break; + } + + if (alloc && (status != AVRC_STS_NO_ERROR) ) + { + GKI_freebuf(p_pkt); + *pp_pkt = NULL; + } + AVRC_TRACE_API1("AVRC_BldResponse: returning %d", status); + return status; +} + +#endif /* (AVRC_METADATA_INCLUDED == TRUE)*/ + diff --git a/stack/avrc/avrc_int.h b/stack/avrc/avrc_int.h index b6c90b187..33eebdc46 100644..100755 --- a/stack/avrc/avrc_int.h +++ b/stack/avrc/avrc_int.h @@ -96,10 +96,31 @@ ** Type definitions *****************************************************************************/ +#if (AVRC_METADATA_INCLUDED == TRUE) +/* type for Metadata fragmentation control block */ +typedef struct +{ + BT_HDR *p_fmsg; /* the fragmented message */ + UINT8 frag_pdu; /* the PDU ID for fragmentation */ + BOOLEAN frag_enabled; /* fragmentation flag */ +} tAVRC_FRAG_CB; + +/* type for Metadata re-assembly control block */ +typedef struct +{ + BT_HDR *p_rmsg; /* the received message */ + UINT16 rasm_offset; /* re-assembly flag, the offset of the start fragment */ + UINT8 rasm_pdu; /* the PDU ID for re-assembly */ +} tAVRC_RASM_CB; +#endif typedef struct { tAVRC_CONN_CB ccb[AVCT_NUM_CONN]; +#if (AVRC_METADATA_INCLUDED == TRUE) + tAVRC_FRAG_CB fcb[AVCT_NUM_CONN]; + tAVRC_RASM_CB rcb[AVCT_NUM_CONN]; +#endif tAVRC_FIND_CBACK *p_cback; /* pointer to application callback */ tSDP_DISCOVERY_DB *p_db; /* pointer to discovery database */ UINT16 service_uuid; /* service UUID to search */ diff --git a/stack/avrc/avrc_opt.c b/stack/avrc/avrc_opt.c index 208a6c223..ff791557a 100644..100755 --- a/stack/avrc/avrc_opt.c +++ b/stack/avrc/avrc_opt.c @@ -18,7 +18,7 @@ /****************************************************************************** * - * nterface to AVRCP optional commands + * Interface to AVRCP optional commands * ******************************************************************************/ #include <string.h> @@ -53,8 +53,13 @@ static BT_HDR * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg) WC_ASSERT(p_msg != NULL); +#if AVRC_METADATA_INCLUDED == TRUE + WC_ASSERT(AVRC_META_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); + if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_META_CMD_POOL_ID)) != NULL) +#else WC_ASSERT(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len)); if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL) +#endif { p_cmd->offset = AVCT_MSG_OFFSET; p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset; diff --git a/stack/avrc/avrc_pars_tg.c b/stack/avrc/avrc_pars_tg.c new file mode 100755 index 000000000..0d9cf3477 --- /dev/null +++ b/stack/avrc/avrc_pars_tg.c @@ -0,0 +1,305 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2013 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ +#include <string.h> + +#include "gki.h" +#include "avrc_api.h" +#include "avrc_defs.h" +#include "avrc_int.h" + +/***************************************************************************** +** Global data +*****************************************************************************/ +#if (AVRC_METADATA_INCLUDED == TRUE) + +/******************************************************************************* +** +** Function avrc_pars_vendor_cmd +** +** Description This function parses the vendor specific commands defined by +** Bluetooth SIG +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +static tAVRC_STS avrc_pars_vendor_cmd(tAVRC_MSG_VENDOR *p_msg, tAVRC_COMMAND *p_result, + UINT8 *p_buf, UINT16 buf_len) +{ + tAVRC_STS status = AVRC_STS_NO_ERROR; + UINT8 *p = p_msg->p_vendor_data; + UINT16 len; + UINT8 xx, yy; + UINT8 *p_u8; + UINT16 *p_u16; + UINT32 u32, u32_2, *p_u32; + tAVRC_APP_SETTING *p_app_set; + UINT16 size_needed; + + p_result->pdu = *p++; + AVRC_TRACE_DEBUG1("avrc_pars_vendor_cmd() pdu:0x%x", p_result->pdu); + if (!AVRC_IsValidAvcType (p_result->pdu, p_msg->hdr.ctype)) + { + AVRC_TRACE_DEBUG0("avrc_pars_vendor_cmd() detects wrong AV/C type!"); + status = AVRC_STS_BAD_CMD; + } + + p++; /* skip the reserved byte */ + BE_STREAM_TO_UINT16 (len, p); + if ((len+4) != (p_msg->vendor_len)) + { + status = AVRC_STS_INTERNAL_ERR; + } + + if (status != AVRC_STS_NO_ERROR) + return status; + + switch (p_result->pdu) + { + case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ + p_result->get_caps.capability_id = *p++; + if (!AVRC_IS_VALID_CAP_ID(p_result->get_caps.capability_id)) + status = AVRC_STS_BAD_PARAM; + else if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ + /* no additional parameters */ + if (len != 0) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ + p_result->list_app_values.attr_id = *p++; + if (!AVRC_IS_VALID_ATTRIBUTE(p_result->list_app_values.attr_id)) + status = AVRC_STS_BAD_PARAM; + else if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ + BE_STREAM_TO_UINT8 (p_result->get_cur_app_val.num_attr, p); + if (len != (p_result->get_cur_app_val.num_attr+1)) + { + status = AVRC_STS_INTERNAL_ERR; + break; + } + p_u8 = p_result->get_cur_app_val.attrs; + for (xx=0, yy=0; xx< p_result->get_cur_app_val.num_attr; xx++) + { + /* only report the valid player app attributes */ + if (AVRC_IsValidPlayerAttr(*p)) + p_u8[yy++] = *p; + p++; + } + p_result->get_cur_app_val.num_attr = yy; + if (yy == 0) + { + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ + BE_STREAM_TO_UINT8 (p_result->set_app_val.num_val, p); + size_needed = sizeof(tAVRC_APP_SETTING); + if (p_buf && (len == ((p_result->set_app_val.num_val<<1) + 1))) + { + p_result->set_app_val.p_vals = (tAVRC_APP_SETTING *)p_buf; + p_app_set = p_result->set_app_val.p_vals; + for (xx=0; ((xx< p_result->set_app_val.num_val) && (buf_len > size_needed)); xx++) + { + p_app_set[xx].attr_id = *p++; + p_app_set[xx].attr_val = *p++; + if (!avrc_is_valid_player_attrib_value(p_app_set[xx].attr_id, p_app_set[xx].attr_val)) + status = AVRC_STS_BAD_PARAM; + } + if (xx != p_result->set_app_val.num_val) + { + AVRC_TRACE_ERROR2("AVRC_PDU_SET_PLAYER_APP_VALUE not enough room:%d orig num_val:%d", + xx, p_result->set_app_val.num_val); + p_result->set_app_val.num_val = xx; + } + } + else + { + AVRC_TRACE_ERROR0("AVRC_PDU_SET_PLAYER_APP_VALUE NULL decode buffer or bad len"); + status = AVRC_STS_INTERNAL_ERR; + } + break; + + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:/* 0x16 */ + if (len < 3) + status = AVRC_STS_INTERNAL_ERR; + else + { + BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.attr_id, p); + if (!AVRC_IS_VALID_ATTRIBUTE(p_result->get_app_val_txt.attr_id)) + status = AVRC_STS_BAD_PARAM; + else + { + BE_STREAM_TO_UINT8 (p_result->get_app_val_txt.num_val, p); + if ( (len - 2/* attr_id & num_val */) != p_result->get_app_val_txt.num_val) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_u8 = p_result->get_app_val_txt.vals; + for (xx=0; xx< p_result->get_app_val_txt.num_val; xx++) + { + p_u8[xx] = *p++; + if (!avrc_is_valid_player_attrib_value(p_result->get_app_val_txt.attr_id, + p_u8[xx])) + { + status = AVRC_STS_BAD_PARAM; + break; + } + } + } + } + } + break; + + case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ + if (len < 3) + status = AVRC_STS_INTERNAL_ERR; + else + { + BE_STREAM_TO_UINT8 (p_result->inform_charset.num_id, p); + if ( (len - 1/* num_id */) != p_result->inform_charset.num_id * 2) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_u16 = p_result->inform_charset.charsets; + if (p_result->inform_charset.num_id > AVRC_MAX_CHARSET_SIZE) + p_result->inform_charset.num_id = AVRC_MAX_CHARSET_SIZE; + for (xx=0; xx< p_result->inform_charset.num_id; xx++) + { + BE_STREAM_TO_UINT16 (p_u16[xx], p); + } + } + } + break; + + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:/* 0x18 */ + if (len != 1) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_result->inform_battery_status.battery_status = *p++; + if (!AVRC_IS_VALID_BATTERY_STATUS(p_result->inform_battery_status.battery_status)) + status = AVRC_STS_BAD_PARAM; + } + break; + + case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ + if (len < 9) /* UID/8 and num_attr/1 */ + status = AVRC_STS_INTERNAL_ERR; + else + { + BE_STREAM_TO_UINT32 (u32, p); + BE_STREAM_TO_UINT32 (u32_2, p); + if (u32== 0 && u32_2 == 0) + { + BE_STREAM_TO_UINT8 (p_result->get_elem_attrs.num_attr, p); + if ( (len - 9/* UID/8 and num_attr/1 */) != (p_result->get_elem_attrs.num_attr * 4)) + status = AVRC_STS_INTERNAL_ERR; + else + { + p_u32 = p_result->get_elem_attrs.attrs; + if (p_result->get_elem_attrs.num_attr > AVRC_MAX_ELEM_ATTR_SIZE) + p_result->get_elem_attrs.num_attr = AVRC_MAX_ELEM_ATTR_SIZE; + for (xx=0; xx< p_result->get_elem_attrs.num_attr; xx++) + { + BE_STREAM_TO_UINT32 (p_u32[xx], p); + } + } + } + else + status = AVRC_STS_NOT_FOUND; + } + break; + + case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ + /* no additional parameters */ + if (len != 0) + status = AVRC_STS_INTERNAL_ERR; + break; + + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + if (len != 5) + status = AVRC_STS_INTERNAL_ERR; + BE_STREAM_TO_UINT8 (p_result->reg_notif.event_id, p); + BE_STREAM_TO_UINT32 (p_result->reg_notif.param, p); + break; + + /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */ + /* case AVRC_PDU_ABORT_CONTINUATION_RSP: 0x41 */ + + default: + status = AVRC_STS_BAD_CMD; + break; + } + + return status; +} + +/******************************************************************************* +** +** Function AVRC_ParsCommand +** +** Description This function is a superset of AVRC_ParsMetadata to parse the command. +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +tAVRC_STS AVRC_ParsCommand (tAVRC_MSG *p_msg, tAVRC_COMMAND *p_result, UINT8 *p_buf, UINT16 buf_len) +{ + tAVRC_STS status = AVRC_STS_INTERNAL_ERR; + UINT16 id; + + if (p_msg && p_result) + { + switch (p_msg->hdr.opcode) + { + case AVRC_OP_VENDOR: /* 0x00 Vendor-dependent commands */ + status = avrc_pars_vendor_cmd(&p_msg->vendor, p_result, p_buf, buf_len); + break; + + case AVRC_OP_PASS_THRU: /* 0x7C panel subunit opcode */ + status = avrc_pars_pass_thru(&p_msg->pass, &id); + if (status == AVRC_STS_NO_ERROR) + { + p_result->pdu = (UINT8)id; + } + break; + + default: + AVRC_TRACE_ERROR1("AVRC_ParsCommand() unknown opcode:0x%x", p_msg->hdr.opcode); + break; + } + p_result->cmd.opcode = p_msg->hdr.opcode; + p_result->cmd.status = status; + } + AVRC_TRACE_DEBUG1("AVRC_ParsCommand() return status:0x%x", status); + return status; +} + +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ + diff --git a/stack/avrc/avrc_sdp.c b/stack/avrc/avrc_sdp.c index 427894c84..e447e48b6 100644..100755 --- a/stack/avrc/avrc_sdp.c +++ b/stack/avrc/avrc_sdp.c @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright (C) 2003-2012 Broadcom Corporation + * Copyright (C) 2003-2013 Broadcom Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,11 @@ tAVRC_CB avrc_cb; const tSDP_PROTOCOL_ELEM avrc_proto_list [] = { {UUID_PROTOCOL_L2CAP, 1, {AVCT_PSM, 0} }, +#if AVRC_METADATA_INCLUDED == TRUE + {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_2, 0} } +#else {UUID_PROTOCOL_AVCTP, 1, {AVCT_REV_1_0, 0} } +#endif }; @@ -212,7 +216,12 @@ UINT16 AVRC_AddRecord(UINT16 service_uuid, char *p_service_name, result &= SDP_AddProtocolList(sdp_handle, AVRC_NUM_PROTO_ELEMS, (tSDP_PROTOCOL_ELEM *)avrc_proto_list); /* add profile descriptor list */ +#if AVRC_METADATA_INCLUDED == TRUE + result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, AVRC_REV_1_3); +#else result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, AVRC_REV_1_0); +#endif + /* add supported categories */ p = temp; diff --git a/stack/avrc/avrc_utils.c b/stack/avrc/avrc_utils.c new file mode 100755 index 000000000..939a26f39 --- /dev/null +++ b/stack/avrc/avrc_utils.c @@ -0,0 +1,240 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2013 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ +#include <string.h> + +#include "gki.h" +#include "avrc_api.h" +#include "avrc_int.h" + + +#if (AVRC_METADATA_INCLUDED == TRUE) + +/************************************************************************** +** +** Function AVRC_IsValidAvcType +** +** Description Check if correct AVC type is specified +** +** Returns returns TRUE if it is valid +** +** +*******************************************************************************/ +BOOLEAN AVRC_IsValidAvcType(UINT8 pdu_id, UINT8 avc_type) +{ + BOOLEAN result=FALSE; + + if (avc_type < AVRC_RSP_NOT_IMPL) /* command msg */ + { + switch (pdu_id) + { + case AVRC_PDU_GET_CAPABILITIES: /* 0x10 */ + case AVRC_PDU_LIST_PLAYER_APP_ATTR: /* 0x11 */ + case AVRC_PDU_LIST_PLAYER_APP_VALUES: /* 0x12 */ + case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE: /* 0x13 */ + case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT: /* 0x15 */ + case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT: /* 0x16 */ + case AVRC_PDU_GET_ELEMENT_ATTR: /* 0x20 */ + case AVRC_PDU_GET_PLAY_STATUS: /* 0x30 */ + if (avc_type == AVRC_CMD_STATUS) + result=TRUE; + break; + + case AVRC_PDU_SET_PLAYER_APP_VALUE: /* 0x14 */ + case AVRC_PDU_INFORM_DISPLAY_CHARSET: /* 0x17 */ + case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT: /* 0x18 */ + case AVRC_PDU_REQUEST_CONTINUATION_RSP: /* 0x40 */ + case AVRC_PDU_ABORT_CONTINUATION_RSP: /* 0x41 */ + if (avc_type == AVRC_CMD_CTRL) + result=TRUE; + break; + + case AVRC_PDU_REGISTER_NOTIFICATION: /* 0x31 */ + if (avc_type == AVRC_CMD_NOTIF) + result=TRUE; + break; + } + } + else /* response msg */ + { + if (avc_type >= AVRC_RSP_NOT_IMPL && + avc_type <= AVRC_RSP_INTERIM ) + result=TRUE; + } + + return result; +} + +/******************************************************************************* +** +** Function avrc_is_valid_player_attrib_value +** +** Description Check if the given attrib value is valid for its attribute +** +** Returns returns TRUE if it is valid +** +*******************************************************************************/ +BOOLEAN avrc_is_valid_player_attrib_value(UINT8 attrib, UINT8 value) +{ + BOOLEAN result=FALSE; + + switch(attrib) + { + case AVRC_PLAYER_SETTING_EQUALIZER: + if ((value > 0) && + (value <= AVRC_PLAYER_VAL_ON)) + result=TRUE; + break; + + case AVRC_PLAYER_SETTING_REPEAT: + if ((value > 0) && + (value <= AVRC_PLAYER_VAL_GROUP_REPEAT)) + result=TRUE; + break; + + case AVRC_PLAYER_SETTING_SHUFFLE: + case AVRC_PLAYER_SETTING_SCAN: + if ((value > 0) && + (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE)) + result=TRUE; + break; + } + + if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && + attrib <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) + result = TRUE; + + if (!result) + AVRC_TRACE_ERROR2( + "avrc_is_valid_player_attrib_value() found not matching attrib(x%x)-value(x%x) pair!", + attrib, value); + + return result; +} + +/******************************************************************************* +** +** Function AVRC_IsValidPlayerAttr +** +** Description Check if the given attrib value is a valid one +** +** Returns returns TRUE if it is valid +** +*******************************************************************************/ +BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr) +{ + BOOLEAN result=FALSE; + + if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) || + (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && attr <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) ) + { + result = TRUE; + } + + return result; +} + + + +/******************************************************************************* +** +** Function avrc_pars_pass_thru +** +** Description This function parses the pass thru commands defined by +** Bluetooth SIG +** +** Returns AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully. +** Otherwise, the error code defined by AVRCP 1.4 +** +*******************************************************************************/ +tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id) +{ + UINT8 *p_data; + UINT32 co_id; + UINT16 id; + tAVRC_STS status = AVRC_STS_BAD_CMD; + + if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN) + { + p_data = p_msg->p_pass_data; + AVRC_BE_STREAM_TO_CO_ID (co_id, p_data); + if (co_id == AVRC_CO_METADATA) + { + BE_STREAM_TO_UINT16 (id, p_data); + if (AVRC_IS_VALID_GROUP(id)) + { + *p_vendor_unique_id = id; + status = AVRC_STS_NO_ERROR; + } + } + } + return status; +} + +/******************************************************************************* +** +** Function avrc_opcode_from_pdu +** +** Description This function returns the opcode of the given pdu +** +** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE +** +*******************************************************************************/ +UINT8 avrc_opcode_from_pdu(UINT8 pdu) +{ + UINT8 opcode = 0; + + switch (pdu) + { + case AVRC_PDU_NEXT_GROUP: + case AVRC_PDU_PREV_GROUP: /* pass thru */ + opcode = AVRC_OP_PASS_THRU; + break; + + default: /* vendor */ + opcode = AVRC_OP_VENDOR; + break; + } + + return opcode; +} + +/******************************************************************************* +** +** Function avrc_is_valid_opcode +** +** Description This function returns the opcode of the given pdu +** +** Returns AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE +** +*******************************************************************************/ +BOOLEAN avrc_is_valid_opcode(UINT8 opcode) +{ + BOOLEAN is_valid = FALSE; + switch (opcode) + { + case AVRC_OP_BROWSE: + case AVRC_OP_PASS_THRU: + case AVRC_OP_VENDOR: + is_valid = TRUE; + break; + } + return is_valid; +} + +#endif /* (AVRC_METADATA_INCLUDED == TRUE) */ + |