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