/****************************************************************************
*NAME    
*    AvrcpGetElementAttributes    
*
*DESCRIPTION
*  API function to request GetElementAttributes. 
*    
*PARAMETERS
*   avrcp            - Task
*   identifier_high -  Element identifier is 8 octets in big-endian format, 
*                      this parameter should be the most significant 4 
*                      octets. Currently only allowed identifier value is 
*                      PLAYING (0x0), so it must be set to 0.
*   identifier_low  - least significant 4 octets of the element identifier.
*                     currently allowed value is only PLAYING(0x0), so it 
*                     must be set to 0.
*   size_attributes - Size of attributes in Bytes
*   attributes      - list of attributes. 
*
*RETURN
*  AVRCP_GET_ELEMENT_ATTRIBUTES_CFM 
*******************************************************************************/
void AvrcpGetElementAttributes(AVRCP    *avrcp,
                               uint32   identifier_high, 
                               uint32   identifier_low, 
                               uint16   size_attributes, 
                               Source   attributes)
{
    uint8 extra_params[AVRCP_GET_ELEMENTS_HDR_SIZE];
    avrcp_status_code status;

    /* Fill in the extra Header for Get Elements which is Identifier and
       number of elements*/
    convertUint32ToUint8Values(&extra_params[0], identifier_high);
    convertUint32ToUint8Values(&extra_params[4], identifier_low);
    extra_params[8] = size_attributes/4;

    status = avrcpMetadataStatusCommand(avrcp, 
                                        AVRCP_GET_ELEMENT_ATTRIBUTES_PDU_ID,
                                        avrcp_get_element_attributes, 
                                        AVRCP_GET_ELEMENTS_HDR_SIZE, 
                                        extra_params,size_attributes,
                                        attributes);

    if (status != avrcp_success)
    {
        avrcpSendCommonFragmentedMetadataCfm(avrcp, status, 
                                            AVRCP_GET_ELEMENT_ATTRIBUTES_CFM, 
                                            0, 0, 0);
    }
}
/****************************************************************************
*NAME    
*    AvrcpConnect    
*
*DESCRIPTION
*  API function to request Continuing Response.
*    
*PARAMETERS
*   avrcp            - Task
*   pdu_id           - PDU_ID of the received fragmented message which requires
*                      a continuation response. 
*
*RETURN
*  AVRCP_REQUEST_CONTINUING_RESPONSE_CFM 
*******************************************************************************/
void AvrcpRequestContinuing(AVRCP *avrcp, uint16 pdu_id)
{
    uint8 params[] = {0};
    avrcp_status_code status;

    params[0] = pdu_id & 0xFF;

    status = avrcpMetadataStatusCommand(avrcp, 
                                    AVRCP_REQUEST_CONTINUING_RESPONSE_PDU_ID,
                                    avrcp_request_continuation, 1, 
                                    params, 0,0);

    if (status != avrcp_success)
    {
        MAKE_AVRCP_MESSAGE(AVRCP_REQUEST_CONTINUING_RESPONSE_CFM);

        message->avrcp = avrcp;
        message->status = status;
        message->pdu_id = params[0];

#ifdef AVRCP_ENABLE_DEPRECATED 
        /* Deprecated fields will be removed later */
        message->transaction = 0;
#endif
        MessageSend(avrcp->clientTask, 
                    AVRCP_REQUEST_CONTINUING_RESPONSE_CFM, message);
    }
}
/****************************************************************************
*NAME    
*    AvrcpGetPlayStatus    
*
*DESCRIPTION
*  API function to request GetPlayStatus
*    
*PARAMETERS
*   avrcp            - Task
*
*RETURN
*  AVRCP_GET_PLAY_STATUS_CFM 
*****************************************************************************/
void AvrcpGetPlayStatus(AVRCP *avrcp)
{
    avrcp_status_code status = avrcpMetadataStatusCommand(avrcp, 
                                                AVRCP_GET_PLAY_STATUS_PDU_ID,
                                                avrcp_get_play_status, 
                                                0, 0, 0, 0);

    if (status != avrcp_success)
    {
        avrcpSendGetPlayStatusCfm(avrcp, status, 0, 0, 0, 0);
    }
}
/****************************************************************************
* NAME    
* AvrcpListAppAttributeRequest    
*
* DESCRIPTION
* API to send ListPlayerApplicationSettingAttributes Command to the TG. On 
* completion this API, library returns the message AVRCP_LIST_APP_ATTRIBUTE_CFM.
* All parameters are described in the header file.
*******************************************************************************/
void AvrcpListAppAttributeRequest( AVRCP *avrcp )
{
    avrcp_status_code status = avrcpMetadataStatusCommand(avrcp,
                                        AVRCP_LIST_APP_ATTRIBUTES_PDU_ID, 
                                        avrcp_list_app_attributes,
                                        0, 0, 0, 0);

    if (status != avrcp_success)
    {
        avrcpSendCommonFragmentedMetadataCfm(avrcp, status, 
                                            AVRCP_LIST_APP_ATTRIBUTE_CFM, 
                                            0, 0, 0);
    }
}
/****************************************************************************
*NAME    
*    AvrcpAbortContinuing    
*
*DESCRIPTION
*  API function to Abort Continuing Response.
*    
*PARAMETERS
*   avrcp            - Task
*   pdu_id           - PDU_ID of the received fragmented message to abort.
*
*RETURN
*  AVRCP_ABORT_CONTINUING_RESPONSE_CFM 
*******************************************************************************/
void AvrcpAbortContinuing(AVRCP *avrcp, uint16 pdu_id)
{
    uint8 params[] = {0};
    avrcp_status_code status;

    params[0] = pdu_id & 0xFF;

    status = avrcpMetadataStatusCommand(avrcp,
                                  AVRCP_ABORT_CONTINUING_RESPONSE_PDU_ID, 
                                  avrcp_abort_continuation, 1, params, 0, 0);

    if (status != avrcp_success)
    {
        avrcpSendCommonMetadataCfm(avrcp, status, 
                                   AVRCP_ABORT_CONTINUING_RESPONSE_CFM);
    }
}
/****************************************************************************
* NAME    
* AvrcpListAppValueRequest    
*
* DESCRIPTION
* API to send ListPlayerApplicationSettingValue  to the CT. 
* All parameters are described in the header file.
*******************************************************************************/
void AvrcpListAppValueRequest(AVRCP *avrcp, uint16 attribute_id)
{
    uint8 status_params[] = {0};
    avrcp_status_code status;

    status_params[0] = attribute_id;

    status = avrcpMetadataStatusCommand(avrcp, AVRCP_LIST_APP_VALUE_PDU_ID,
                                        avrcp_list_app_values, 
                                        sizeof(status_params), 
                                        status_params, 0, 0);

    if (status != avrcp_success)
    {
        avrcpSendCommonFragmentedMetadataCfm(avrcp, status, 
                                             AVRCP_LIST_APP_VALUE_CFM, 
                                             0, 0, 0);
    }
}
/****************************************************************************
 *NAME    
 *    AvrcpRegisterNotification    
 *
 *DESCRIPTION
 *  CT shall use this API function to register Event Notifications 
 *
 *PARAMETERS
 * avrcp            -   AVRCP Entity
 * event_id         -   Event to be registered with TG for notifications.
 * playback_interval-   Only applicable to EVENT_PLAYBACK_POS_CHANGED 
 *
 *MESSAGE RETURNED
 * EVENT_IND messages on Event notifications from TG.
*****************************************************************************/
void AvrcpRegisterNotification(AVRCP                    *avrcp, 
                               avrcp_supported_events   event_id, 
                               uint32                   playback_interval)
{
    uint8 params[5];
    avrcp_status_code status;

    params[0] = event_id & 0xFF;
    convertUint32ToUint8Values(&params[1], playback_interval);

    status = avrcpMetadataStatusCommand(avrcp, 
                                        AVRCP_REGISTER_NOTIFICATION_PDU_ID, 
                                        event_id + avrcp_events_start_dummy, 
                                        sizeof(params), params, 0, 0);

    if (status != avrcp_success)
    {
        avrcpSendRegisterNotificationFailCfm(avrcp, status, event_id);
    }
}
/****************************************************************************
*NAME    
*    AvrcpGetAppValueRequest    
*
*DESCRIPTION
*  API function to send GetCurrentPlayerApplicationSettingValue Request from CT.
*  All parameters are described in the header file.
******************************************************************************/
void AvrcpGetAppValueRequest( AVRCP   *avrcp, 
                              uint16  size_attributes, 
                              Source  attributes )
{
    uint8 extra_params[AVRCP_APP_NUM_ATTR_HDR_SIZE];
    avrcp_status_code status;

    extra_params[0] = size_attributes;

    status = avrcpMetadataStatusCommand(avrcp, AVRCP_GET_APP_VALUE_PDU_ID, 
                                        avrcp_get_app_values, 
                                        AVRCP_APP_NUM_ATTR_HDR_SIZE, 
                                        extra_params,
                                        size_attributes,
                                        attributes);

    if (status != avrcp_success)
    {
        avrcpSendCommonFragmentedMetadataCfm(avrcp, status,
                                             AVRCP_GET_APP_VALUE_CFM, 0, 0, 0);
    }
}
/****************************************************************************
*NAME    
*    AvrcpGetAppValueText    
*
*DESCRIPTION
*  API function to send GetAppSettingValueText Request from CT.
*  All parameters are described in the header file.   
*****************************************************************************/
void AvrcpGetAppValueTextRequest(   AVRCP *avrcp, 
                                    uint16 attribute_id, 
                                    uint16 size_values, 
                                    Source values )
{
    uint8 extra_params[AVRCP_APP_VAL_TXT_HDR_SIZE];
    avrcp_status_code status;

    extra_params[0] = attribute_id;
    extra_params[1] = size_values;

    status = avrcpMetadataStatusCommand(avrcp, 
                                        AVRCP_GET_APP_VALUE_TEXT_PDU_ID, 
                                        avrcp_get_app_value_text,  
                                         AVRCP_APP_VAL_TXT_HDR_SIZE,
                                        extra_params,size_values,values);

    if (status != avrcp_success)
    {
        avrcpSendCommonFragmentedMetadataCfm(avrcp, status, 
                                              AVRCP_GET_APP_VALUE_TEXT_CFM, 
                                             0, 0, 0);
    }
}