Home | History | Annotate | Download | only in avrc
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2006-2013 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 #include <string.h>
     19 
     20 #include "gki.h"
     21 #include "avrc_api.h"
     22 #include "avrc_defs.h"
     23 #include "avrc_int.h"
     24 
     25 /*****************************************************************************
     26 **  Global data
     27 *****************************************************************************/
     28 
     29 #if (AVRC_METADATA_INCLUDED == TRUE)
     30 
     31 /*******************************************************************************
     32 **
     33 ** Function         avrc_pars_vendor_rsp
     34 **
     35 ** Description      This function parses the vendor specific commands defined by
     36 **                  Bluetooth SIG
     37 **
     38 ** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
     39 **                  Otherwise, the error code defined by AVRCP 1.4
     40 **
     41 *******************************************************************************/
     42 static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len)
     43 {
     44     tAVRC_STS  status = AVRC_STS_NO_ERROR;
     45     UINT8   *p = p_msg->p_vendor_data;
     46     UINT16  len;
     47     UINT8   xx, yy;
     48     tAVRC_NOTIF_RSP_PARAM   *p_param;
     49     tAVRC_APP_SETTING       *p_app_set;
     50     tAVRC_APP_SETTING_TEXT  *p_app_txt;
     51     tAVRC_ATTR_ENTRY        *p_entry;
     52     UINT32  *p_u32;
     53     UINT8   *p_u8;
     54     UINT16  size_needed;
     55     UINT8 eventid=0;
     56 
     57     BE_STREAM_TO_UINT8 (p_result->pdu, p);
     58     p++; /* skip the reserved/packe_type byte */
     59     BE_STREAM_TO_UINT16 (len, p);
     60     AVRC_TRACE_DEBUG4("avrc_pars_vendor_rsp() ctype:0x%x pdu:0x%x, len:%d/0x%x", p_msg->hdr.ctype, p_result->pdu, len, len);
     61     if (p_msg->hdr.ctype == AVRC_RSP_REJ)
     62     {
     63         p_result->rsp.status = *p;
     64         return p_result->rsp.status;
     65     }
     66 
     67     switch (p_result->pdu)
     68     {
     69     /* case AVRC_PDU_REQUEST_CONTINUATION_RSP: 0x40 */
     70     /* case AVRC_PDU_ABORT_CONTINUATION_RSP:   0x41 */
     71 
     72 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
     73     case AVRC_PDU_SET_ABSOLUTE_VOLUME:      /* 0x50 */
     74         if (len != 1)
     75             status = AVRC_STS_INTERNAL_ERR;
     76         else
     77         {
     78             BE_STREAM_TO_UINT8 (p_result->volume.volume, p);
     79         }
     80         break;
     81 #endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
     82 
     83     case AVRC_PDU_REGISTER_NOTIFICATION:    /* 0x31 */
     84 #if (AVRC_ADV_CTRL_INCLUDED == TRUE)
     85         BE_STREAM_TO_UINT8 (eventid, p);
     86         if(AVRC_EVT_VOLUME_CHANGE==eventid
     87             && (AVRC_RSP_CHANGED==p_msg->hdr.ctype || AVRC_RSP_INTERIM==p_msg->hdr.ctype
     88             || AVRC_RSP_REJ==p_msg->hdr.ctype || AVRC_RSP_NOT_IMPL==p_msg->hdr.ctype))
     89         {
     90             p_result->reg_notif.status=p_msg->hdr.ctype;
     91             p_result->reg_notif.event_id=eventid;
     92             BE_STREAM_TO_UINT8 (p_result->reg_notif.param.volume, p);
     93         }
     94         AVRC_TRACE_DEBUG2("avrc_pars_vendor_rsp PDU reg notif response:event %x, volume %x",eventid,
     95             p_result->reg_notif.param.volume);
     96 #endif /* (AVRC_ADV_CTRL_INCLUDED == TRUE) */
     97         break;
     98     default:
     99         status = AVRC_STS_BAD_CMD;
    100         break;
    101     }
    102 
    103     return status;
    104 }
    105 
    106 /*******************************************************************************
    107 **
    108 ** Function         AVRC_ParsResponse
    109 **
    110 ** Description      This function is a superset of AVRC_ParsMetadata to parse the response.
    111 **
    112 ** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
    113 **                  Otherwise, the error code defined by AVRCP 1.4
    114 **
    115 *******************************************************************************/
    116 tAVRC_STS AVRC_ParsResponse (tAVRC_MSG *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len)
    117 {
    118     tAVRC_STS  status = AVRC_STS_INTERNAL_ERR;
    119     UINT16  id;
    120 
    121     if (p_msg && p_result)
    122     {
    123         switch (p_msg->hdr.opcode)
    124         {
    125         case AVRC_OP_VENDOR:     /*  0x00    Vendor-dependent commands */
    126             status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result, p_buf, buf_len);
    127             break;
    128 
    129         case AVRC_OP_PASS_THRU:  /*  0x7C    panel subunit opcode */
    130             status = avrc_pars_pass_thru(&p_msg->pass, &id);
    131             if (status == AVRC_STS_NO_ERROR)
    132             {
    133                 p_result->pdu = (UINT8)id;
    134             }
    135             break;
    136 
    137         default:
    138             AVRC_TRACE_ERROR1("AVRC_ParsResponse() unknown opcode:0x%x", p_msg->hdr.opcode);
    139             break;
    140         }
    141         p_result->rsp.opcode = p_msg->hdr.opcode;
    142     p_result->rsp.status = status;
    143     }
    144     return status;
    145 }
    146 
    147 
    148 #endif /* (AVRC_METADATA_INCLUDED == TRUE) */
    149