Home | History | Annotate | Download | only in avrc
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2003-2012 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 
     19 /******************************************************************************
     20  *
     21  *  nterface to AVRCP optional commands
     22  *
     23  ******************************************************************************/
     24 #include <string.h>
     25 
     26 #include "gki.h"
     27 #include "avrc_api.h"
     28 #include "avrc_int.h"
     29 
     30 #include "wcassert.h"
     31 
     32 
     33 /******************************************************************************
     34 **
     35 ** Function         avrc_vendor_msg
     36 **
     37 ** Description      Compose a VENDOR DEPENDENT command according to p_msg
     38 **
     39 **                  Input Parameters:
     40 **                      p_msg: Pointer to VENDOR DEPENDENT message structure.
     41 **
     42 **                  Output Parameters:
     43 **                      None.
     44 **
     45 ** Returns          pointer to a valid GKI buffer if successful.
     46 **                  NULL if p_msg is NULL.
     47 **
     48 ******************************************************************************/
     49 static BT_HDR  * avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg)
     50 {
     51     BT_HDR  *p_cmd;
     52     UINT8   *p_data;
     53 
     54     WC_ASSERT(p_msg != NULL);
     55 
     56     WC_ASSERT(AVRC_CMD_POOL_SIZE > (AVRC_MIN_CMD_LEN+p_msg->vendor_len));
     57     if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL)
     58     {
     59         p_cmd->offset   = AVCT_MSG_OFFSET;
     60         p_data          = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
     61         *p_data++       = (p_msg->hdr.ctype & AVRC_CTYPE_MASK);
     62         *p_data++       = (p_msg->hdr.subunit_type << AVRC_SUBTYPE_SHIFT) | p_msg->hdr.subunit_id;
     63         *p_data++       = AVRC_OP_VENDOR;
     64         AVRC_CO_ID_TO_BE_STREAM(p_data, p_msg->company_id);
     65         if(p_msg->vendor_len && p_msg->p_vendor_data)
     66         {
     67             memcpy(p_data, p_msg->p_vendor_data, p_msg->vendor_len);
     68         }
     69         p_cmd->len  = (UINT16) (p_data + p_msg->vendor_len - (UINT8 *)(p_cmd + 1) - p_cmd->offset);
     70         p_cmd->layer_specific   = AVCT_DATA_CTRL;
     71     }
     72     return p_cmd;
     73 }
     74 
     75 /******************************************************************************
     76 **
     77 ** Function         AVRC_UnitCmd
     78 **
     79 ** Description      Send a UNIT INFO command to the peer device.  This
     80 **                  function can only be called for controller role connections.
     81 **                  Any response message from the peer is passed back through
     82 **                  the tAVRC_MSG_CBACK callback function.
     83 **
     84 **                  Input Parameters:
     85 **                      handle: Handle of this connection.
     86 **
     87 **                      label: Transaction label.
     88 **
     89 **                  Output Parameters:
     90 **                      None.
     91 **
     92 ** Returns          AVRC_SUCCESS if successful.
     93 **                  AVRC_BAD_HANDLE if handle is invalid.
     94 **
     95 ******************************************************************************/
     96 UINT16 AVRC_UnitCmd(UINT8 handle, UINT8 label)
     97 {
     98     BT_HDR  *p_cmd;
     99     UINT8   *p_data;
    100 
    101     if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL)
    102     {
    103         p_cmd->offset   = AVCT_MSG_OFFSET;
    104         p_data          = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
    105         *p_data++       = AVRC_CMD_STATUS;
    106         /* unit & id ignore */
    107         *p_data++       = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE;
    108         *p_data++       = AVRC_OP_UNIT_INFO;
    109         memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_UNIT_OPRND_BYTES);
    110         p_cmd->len      = p_data + AVRC_UNIT_OPRND_BYTES - (UINT8 *)(p_cmd + 1) - p_cmd->offset;
    111         p_cmd->layer_specific   = AVCT_DATA_CTRL;
    112     }
    113     return AVCT_MsgReq( handle, label, AVCT_CMD, p_cmd);
    114 }
    115 
    116 /******************************************************************************
    117 **
    118 ** Function         AVRC_SubCmd
    119 **
    120 ** Description      Send a SUBUNIT INFO command to the peer device.  This
    121 **                  function can only be called for controller role connections.
    122 **                  Any response message from the peer is passed back through
    123 **                  the tAVRC_MSG_CBACK callback function.
    124 **
    125 **                  Input Parameters:
    126 **                      handle: Handle of this connection.
    127 **
    128 **                      label: Transaction label.
    129 **
    130 **                      page: Specifies which part of the subunit type table
    131 **                      is requested.  For AVRCP it is typically zero.
    132 **                      Value range is 0-7.
    133 **
    134 **                  Output Parameters:
    135 **                      None.
    136 **
    137 ** Returns          AVRC_SUCCESS if successful.
    138 **                  AVRC_BAD_HANDLE if handle is invalid.
    139 **
    140 ******************************************************************************/
    141 UINT16 AVRC_SubCmd(UINT8 handle, UINT8 label, UINT8 page)
    142 {
    143     BT_HDR  *p_cmd;
    144     UINT8   *p_data;
    145 
    146     if ((p_cmd = (BT_HDR *) GKI_getpoolbuf(AVRC_CMD_POOL_ID)) != NULL)
    147     {
    148         p_cmd->offset   = AVCT_MSG_OFFSET;
    149         p_data          = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
    150         *p_data++       = AVRC_CMD_STATUS;
    151         /* unit & id ignore */
    152         *p_data++       = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE;
    153         *p_data++       = AVRC_OP_SUB_INFO;
    154         *p_data++       = ((page&AVRC_SUB_PAGE_MASK) << AVRC_SUB_PAGE_SHIFT) | AVRC_SUB_EXT_CODE;
    155         memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_SUB_OPRND_BYTES);
    156         p_cmd->len      = p_data + AVRC_SUB_OPRND_BYTES - (UINT8 *)(p_cmd + 1) - p_cmd->offset;
    157         p_cmd->layer_specific   = AVCT_DATA_CTRL;
    158     }
    159     return AVCT_MsgReq( handle, label, AVCT_CMD, p_cmd);
    160 }
    161 
    162 /******************************************************************************
    163 **
    164 ** Function         AVRC_VendorCmd
    165 **
    166 ** Description      Send a VENDOR DEPENDENT command to the peer device.  This
    167 **                  function can only be called for controller role connections.
    168 **                  Any response message from the peer is passed back through
    169 **                  the tAVRC_MSG_CBACK callback function.
    170 **
    171 **                  Input Parameters:
    172 **                      handle: Handle of this connection.
    173 **
    174 **                      label: Transaction label.
    175 **
    176 **                      p_msg: Pointer to VENDOR DEPENDENT message structure.
    177 **
    178 **                  Output Parameters:
    179 **                      None.
    180 **
    181 ** Returns          AVRC_SUCCESS if successful.
    182 **                  AVRC_BAD_HANDLE if handle is invalid.
    183 **
    184 ******************************************************************************/
    185 UINT16 AVRC_VendorCmd(UINT8  handle, UINT8  label, tAVRC_MSG_VENDOR *p_msg)
    186 {
    187     BT_HDR *p_buf = avrc_vendor_msg(p_msg);
    188     if (p_buf)
    189         return AVCT_MsgReq( handle, label, AVCT_CMD, p_buf);
    190     else
    191         return AVCT_NO_RESOURCES;
    192 }
    193 
    194 
    195 /******************************************************************************
    196 **
    197 ** Function         AVRC_VendorRsp
    198 **
    199 ** Description      Send a VENDOR DEPENDENT response to the peer device.  This
    200 **                  function can only be called for target role connections.
    201 **                  This function must be called when a VENDOR DEPENDENT
    202 **                  command message is received from the peer through the
    203 **                  tAVRC_MSG_CBACK callback function.
    204 **
    205 **                  Input Parameters:
    206 **                      handle: Handle of this connection.
    207 **
    208 **                      label: Transaction label.  Must be the same value as
    209 **                      passed with the command message in the callback function.
    210 **
    211 **                      p_msg: Pointer to VENDOR DEPENDENT message structure.
    212 **
    213 **                  Output Parameters:
    214 **                      None.
    215 **
    216 ** Returns          AVRC_SUCCESS if successful.
    217 **                  AVRC_BAD_HANDLE if handle is invalid.
    218 **
    219 ******************************************************************************/
    220 UINT16 AVRC_VendorRsp(UINT8  handle, UINT8  label, tAVRC_MSG_VENDOR *p_msg)
    221 {
    222     BT_HDR *p_buf = avrc_vendor_msg(p_msg);
    223     if (p_buf)
    224         return AVCT_MsgReq( handle, label, AVCT_RSP, p_buf);
    225     else
    226         return AVCT_NO_RESOURCES;
    227 }
    228 
    229 
    230 
    231