Home | History | Annotate | Download | only in avrc
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2003-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_int.h"
     23 
     24 
     25 #if (AVRC_METADATA_INCLUDED == TRUE)
     26 
     27 /**************************************************************************
     28 **
     29 ** Function         AVRC_IsValidAvcType
     30 **
     31 ** Description      Check if correct AVC type is specified
     32 **
     33 ** Returns          returns TRUE if it is valid
     34 **
     35 **
     36 *******************************************************************************/
     37 BOOLEAN AVRC_IsValidAvcType(UINT8 pdu_id, UINT8 avc_type)
     38 {
     39     BOOLEAN result=FALSE;
     40 
     41     if (avc_type < AVRC_RSP_NOT_IMPL) /* command msg */
     42     {
     43         switch (pdu_id)
     44         {
     45         case AVRC_PDU_GET_CAPABILITIES:            /* 0x10 */
     46         case AVRC_PDU_LIST_PLAYER_APP_ATTR:        /* 0x11 */
     47         case AVRC_PDU_LIST_PLAYER_APP_VALUES:      /* 0x12 */
     48         case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:    /* 0x13 */
     49         case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:    /* 0x15 */
     50         case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:   /* 0x16 */
     51         case AVRC_PDU_GET_ELEMENT_ATTR:            /* 0x20 */
     52         case AVRC_PDU_GET_PLAY_STATUS:             /* 0x30 */
     53              if (avc_type == AVRC_CMD_STATUS)
     54                 result=TRUE;
     55              break;
     56 
     57         case AVRC_PDU_SET_PLAYER_APP_VALUE:        /* 0x14 */
     58         case AVRC_PDU_INFORM_DISPLAY_CHARSET:      /* 0x17 */
     59         case AVRC_PDU_INFORM_BATTERY_STAT_OF_CT:   /* 0x18 */
     60         case AVRC_PDU_REQUEST_CONTINUATION_RSP:    /* 0x40 */
     61         case AVRC_PDU_ABORT_CONTINUATION_RSP:      /* 0x41 */
     62              if (avc_type == AVRC_CMD_CTRL)
     63                 result=TRUE;
     64              break;
     65 
     66         case AVRC_PDU_REGISTER_NOTIFICATION:       /* 0x31 */
     67              if (avc_type == AVRC_CMD_NOTIF)
     68                 result=TRUE;
     69              break;
     70         }
     71     }
     72     else  /* response msg */
     73     {
     74         if (avc_type >= AVRC_RSP_NOT_IMPL  &&
     75            avc_type <= AVRC_RSP_INTERIM    )
     76            result=TRUE;
     77     }
     78 
     79     return result;
     80 }
     81 
     82 /*******************************************************************************
     83 **
     84 ** Function         avrc_is_valid_player_attrib_value
     85 **
     86 ** Description      Check if the given attrib value is valid for its attribute
     87 **
     88 ** Returns          returns TRUE if it is valid
     89 **
     90 *******************************************************************************/
     91 BOOLEAN avrc_is_valid_player_attrib_value(UINT8 attrib, UINT8 value)
     92 {
     93     BOOLEAN result=FALSE;
     94 
     95     switch(attrib)
     96     {
     97     case AVRC_PLAYER_SETTING_EQUALIZER:
     98          if ((value > 0)  &&
     99             (value <= AVRC_PLAYER_VAL_ON))
    100             result=TRUE;
    101          break;
    102 
    103     case AVRC_PLAYER_SETTING_REPEAT:
    104          if ((value > 0)  &&
    105             (value <= AVRC_PLAYER_VAL_GROUP_REPEAT))
    106             result=TRUE;
    107          break;
    108 
    109     case AVRC_PLAYER_SETTING_SHUFFLE:
    110     case AVRC_PLAYER_SETTING_SCAN:
    111          if ((value > 0)  &&
    112             (value <= AVRC_PLAYER_VAL_GROUP_SHUFFLE))
    113             result=TRUE;
    114          break;
    115     }
    116 
    117     if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT &&
    118        attrib <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT)
    119        result = TRUE;
    120 
    121     if (!result)
    122         AVRC_TRACE_ERROR2(
    123             "avrc_is_valid_player_attrib_value() found not matching attrib(x%x)-value(x%x) pair!",
    124             attrib, value);
    125 
    126     return result;
    127 }
    128 
    129 /*******************************************************************************
    130 **
    131 ** Function         AVRC_IsValidPlayerAttr
    132 **
    133 ** Description      Check if the given attrib value is a valid one
    134 **
    135 ** Returns          returns TRUE if it is valid
    136 **
    137 *******************************************************************************/
    138 BOOLEAN AVRC_IsValidPlayerAttr(UINT8 attr)
    139 {
    140     BOOLEAN result=FALSE;
    141 
    142     if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) ||
    143          (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && attr <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) )
    144     {
    145        result = TRUE;
    146     }
    147 
    148     return result;
    149 }
    150 
    151 
    152 
    153 /*******************************************************************************
    154 **
    155 ** Function         avrc_pars_pass_thru
    156 **
    157 ** Description      This function parses the pass thru commands defined by
    158 **                  Bluetooth SIG
    159 **
    160 ** Returns          AVRC_STS_NO_ERROR, if the message in p_data is parsed successfully.
    161 **                  Otherwise, the error code defined by AVRCP 1.4
    162 **
    163 *******************************************************************************/
    164 tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id)
    165 {
    166     UINT8      *p_data;
    167     UINT32      co_id;
    168     UINT16      id;
    169     tAVRC_STS  status = AVRC_STS_BAD_CMD;
    170 
    171     if (p_msg->op_id == AVRC_ID_VENDOR && p_msg->pass_len == AVRC_PASS_THRU_GROUP_LEN)
    172     {
    173         p_data = p_msg->p_pass_data;
    174         AVRC_BE_STREAM_TO_CO_ID (co_id, p_data);
    175         if (co_id == AVRC_CO_METADATA)
    176         {
    177             BE_STREAM_TO_UINT16 (id, p_data);
    178             if (AVRC_IS_VALID_GROUP(id))
    179             {
    180                 *p_vendor_unique_id = id;
    181                 status = AVRC_STS_NO_ERROR;
    182             }
    183         }
    184     }
    185     return status;
    186 }
    187 
    188 /*******************************************************************************
    189 **
    190 ** Function         avrc_opcode_from_pdu
    191 **
    192 ** Description      This function returns the opcode of the given pdu
    193 **
    194 ** Returns          AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE
    195 **
    196 *******************************************************************************/
    197 UINT8 avrc_opcode_from_pdu(UINT8 pdu)
    198 {
    199     UINT8 opcode = 0;
    200 
    201     switch (pdu)
    202     {
    203     case AVRC_PDU_NEXT_GROUP:
    204     case AVRC_PDU_PREV_GROUP: /* pass thru */
    205         opcode  = AVRC_OP_PASS_THRU;
    206         break;
    207 
    208     default: /* vendor */
    209         opcode  = AVRC_OP_VENDOR;
    210         break;
    211     }
    212 
    213     return opcode;
    214 }
    215 
    216 /*******************************************************************************
    217 **
    218 ** Function         avrc_is_valid_opcode
    219 **
    220 ** Description      This function returns the opcode of the given pdu
    221 **
    222 ** Returns          AVRC_OP_VENDOR, AVRC_OP_PASS_THRU or AVRC_OP_BROWSE
    223 **
    224 *******************************************************************************/
    225 BOOLEAN avrc_is_valid_opcode(UINT8 opcode)
    226 {
    227     BOOLEAN is_valid = FALSE;
    228     switch (opcode)
    229     {
    230     case AVRC_OP_BROWSE:
    231     case AVRC_OP_PASS_THRU:
    232     case AVRC_OP_VENDOR:
    233         is_valid = TRUE;
    234         break;
    235     }
    236     return is_valid;
    237 }
    238 
    239 #endif /* (AVRC_METADATA_INCLUDED == TRUE) */
    240 
    241