Пример #1
0
/******************************************************************************
**
** 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_DEBUG ("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
    ** Response" 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));
}
Пример #2
0
/******************************************************************************
**
** Function         avrc_vendor_msg
**
** Description      Compose a VENDOR DEPENDENT command according to p_msg
**
**                  Input Parameters:
**                      p_msg: Pointer to VENDOR DEPENDENT message structure.
**
**                  Output Parameters:
**                      None.
**
** Returns          pointer to a valid GKI buffer if successful.
**                  NULL if p_msg is NULL.
**
******************************************************************************/
static BT_HDR   *avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg)
{
    BT_HDR  *p_cmd;
    UINT8   *p_data;

    assert(p_msg != NULL);

#if AVRC_METADATA_INCLUDED == TRUE
    assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
    if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_META_CMD_BUF_SIZE)) != NULL)
#else
    assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
    if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL)
#endif
    {
        p_cmd->offset   = AVCT_MSG_OFFSET;
        p_data          = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
        *p_data++       = (p_msg->hdr.ctype & AVRC_CTYPE_MASK);
        *p_data++       = (p_msg->hdr.subunit_type << AVRC_SUBTYPE_SHIFT) | p_msg->hdr.subunit_id;
        *p_data++       = AVRC_OP_VENDOR;
        AVRC_CO_ID_TO_BE_STREAM(p_data, p_msg->company_id);
        if (p_msg->vendor_len && p_msg->p_vendor_data) {
            memcpy(p_data, p_msg->p_vendor_data, p_msg->vendor_len);
        }
        p_cmd->len  = (UINT16) (p_data + p_msg->vendor_len - (UINT8 *)(p_cmd + 1) - p_cmd->offset);
        p_cmd->layer_specific   = AVCT_DATA_CTRL;
    }
    return p_cmd;
}
Пример #3
0
/******************************************************************************
**
** Function         avrc_msg_cback
**
** Description      This is the callback function used by AVCTP to report
**                  received AV control messages.
**
** Returns          Nothing.
**
******************************************************************************/
static void avrc_msg_cback(UINT8 handle, UINT8 label, UINT8 cr,
                               BT_HDR *p_pkt)
{
    UINT8       opcode;
    tAVRC_MSG   msg;
    UINT8       *p_data;
    UINT8       *p_begin;
    BOOLEAN     drop = FALSE;
    BOOLEAN     free = TRUE;
    BT_HDR      *p_rsp = NULL;
    UINT8       *p_rsp_data;
    int         xx;
    BOOLEAN     reject = FALSE;
#if (BT_USE_TRACES == TRUE)
    char        *p_drop_msg = "dropped";
#endif
    tAVRC_MSG_VENDOR *p_msg = &msg.vendor;

    if (cr == AVCT_CMD &&
        (p_pkt->layer_specific & AVCT_DATA_CTRL && AVRC_PACKET_LEN < sizeof(p_pkt->len)))
    {
        /* Ignore the invalid AV/C command frame */
#if (BT_USE_TRACES == TRUE)
        p_drop_msg = "dropped - too long AV/C cmd frame size";
#endif
        GKI_freebuf(p_pkt);
        return;
    }

    if (cr == AVCT_REJ)
    {
        /* The peer thinks that this PID is no longer open - remove this handle */
        /*  */
        GKI_freebuf(p_pkt);
        AVCT_RemoveConn(handle);
        return;
    }

    p_data  = (UINT8 *)(p_pkt+1) + p_pkt->offset;
    memset(&msg, 0, sizeof(tAVRC_MSG) );
    {
        msg.hdr.ctype           = p_data[0] & AVRC_CTYPE_MASK;
        AVRC_TRACE_DEBUG4("avrc_msg_cback handle:%d, ctype:%d, offset:%d, len: %d",
                handle, msg.hdr.ctype, p_pkt->offset, p_pkt->len);
        msg.hdr.subunit_type    = (p_data[1] & AVRC_SUBTYPE_MASK) >> AVRC_SUBTYPE_SHIFT;
        msg.hdr.subunit_id      = p_data[1] & AVRC_SUBID_MASK;
        opcode                  = p_data[2];
    }

    if ( ((avrc_cb.ccb[handle].control & AVRC_CT_TARGET) && (cr == AVCT_CMD)) ||
        ((avrc_cb.ccb[handle].control & AVRC_CT_CONTROL) && (cr == AVCT_RSP)) )
    {

        switch(opcode)
        {
        case AVRC_OP_UNIT_INFO:
            if (cr == AVCT_CMD)
            {
                /* send the response to the peer */
                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 */
                *p_rsp_data++   = 7;
                /* Panel subunit & id=0 */
                *p_rsp_data++   = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT);
                AVRC_CO_ID_TO_BE_STREAM(p_rsp_data, avrc_cb.ccb[handle].company_id);
                p_rsp->len      = (UINT16) (p_rsp_data - (UINT8 *)(p_rsp + 1) - p_rsp->offset);
                cr = AVCT_RSP;
#if (BT_USE_TRACES == TRUE)
                p_drop_msg = "auto respond";
#endif
            }
            else
            {
                /* parse response */
                p_data += 4; /* 3 bytes: ctype, subunit*, opcode + octet 3 (is 7)*/
                msg.unit.unit_type  = (*p_data & AVRC_SUBTYPE_MASK) >> AVRC_SUBTYPE_SHIFT;
                msg.unit.unit       = *p_data & AVRC_SUBID_MASK;
                p_data++;
                AVRC_BE_STREAM_TO_CO_ID(msg.unit.company_id, p_data);
            }
            break;

        case AVRC_OP_SUB_INFO:
            if (cr == AVCT_CMD)
            {
                /* send the response to the peer */
                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_SUB_INFO, set (page & extention code) */
                p_rsp_data      = avrc_get_data_ptr(p_pkt) + 4;
                /* Panel subunit & id=0 */
                *p_rsp_data++   = (AVRC_SUB_PANEL << AVRC_SUBTYPE_SHIFT);
                memset(p_rsp_data, AVRC_CMD_OPRND_PAD, AVRC_SUBRSP_OPRND_BYTES);
                p_rsp_data      += AVRC_SUBRSP_OPRND_BYTES;
                p_rsp->len      = (UINT16) (p_rsp_data - (UINT8 *)(p_rsp + 1) - p_rsp->offset);
                cr = AVCT_RSP;
#if (BT_USE_TRACES == TRUE)
                p_drop_msg = "auto responded";
#endif
            }
            else
            {
                /* parse response */
                p_data += AVRC_AVC_HDR_SIZE; /* 3 bytes: ctype, subunit*, opcode */
                msg.sub.page    = (*p_data++ >> AVRC_SUB_PAGE_SHIFT) & AVRC_SUB_PAGE_MASK;
                xx      = 0;
                while (*p_data != AVRC_CMD_OPRND_PAD && xx<AVRC_SUB_TYPE_LEN)
                {
                    msg.sub.subunit_type[xx] = *p_data++ >> AVRC_SUBTYPE_SHIFT;
                    if (msg.sub.subunit_type[xx] == AVRC_SUB_PANEL)
                        msg.sub.panel   = TRUE;
                    xx++;
                }
            }
            break;

        case AVRC_OP_VENDOR:
            p_data  = (UINT8 *)(p_pkt+1) + p_pkt->offset;
            p_begin = p_data;
            if (p_pkt->len < AVRC_VENDOR_HDR_SIZE) /* 6 = ctype, subunit*, opcode & CO_ID */
            {
                if (cr == AVCT_CMD)
                    reject = TRUE;
                else
                    drop = TRUE;
                break;
            }
            p_data += AVRC_AVC_HDR_SIZE; /* skip the first 3 bytes: ctype, subunit*, opcode */
            AVRC_BE_STREAM_TO_CO_ID(p_msg->company_id, p_data);
            p_msg->p_vendor_data   = p_data;
            p_msg->vendor_len      = p_pkt->len - (p_data - p_begin);

            break;

        case AVRC_OP_PASS_THRU:
            if (p_pkt->len < 5) /* 3 bytes: ctype, subunit*, opcode & op_id & len */
            {
                if (cr == AVCT_CMD)
                    reject = TRUE;
                else
                    drop = TRUE;
                break;
            }
            p_data += AVRC_AVC_HDR_SIZE; /* skip the first 3 bytes: ctype, subunit*, opcode */
            msg.pass.op_id  = (AVRC_PASS_OP_ID_MASK & *p_data);
            if (AVRC_PASS_STATE_MASK & *p_data)
                msg.pass.state  = TRUE;
            else
                msg.pass.state  = FALSE;
            p_data++;
            msg.pass.pass_len    = *p_data++;
            if (msg.pass.pass_len != p_pkt->len - 5)
                msg.pass.pass_len = p_pkt->len - 5;
            if (msg.pass.pass_len)
                msg.pass.p_pass_data = p_data;
            else
                msg.pass.p_pass_data = NULL;
            break;


        default:
            if ((avrc_cb.ccb[handle].control & AVRC_CT_TARGET) && (cr == AVCT_CMD))
            {
                /* reject unsupported opcode */
                reject = TRUE;
            }
            drop    = TRUE;
            break;
        }
    }
    else /* drop the event */
    {