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 "common/bt_target.h"
26 #include <string.h>
27 #include "stack/avrc_api.h"
28 #include "avrc_int.h"
29 #include "osi/allocator.h"
30
31 #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
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 ******************************************************************************/
avrc_vendor_msg(tAVRC_MSG_VENDOR * p_msg)49 static BT_HDR *avrc_vendor_msg(tAVRC_MSG_VENDOR *p_msg)
50 {
51 BT_HDR *p_cmd;
52 UINT8 *p_data;
53
54 assert(p_msg != NULL);
55
56 #if AVRC_METADATA_INCLUDED == TRUE
57 assert(AVRC_META_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
58 if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_META_CMD_BUF_SIZE)) != NULL)
59 #else
60 assert(AVRC_CMD_BUF_SIZE > (AVRC_MIN_CMD_LEN + p_msg->vendor_len));
61 if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL)
62 #endif
63 {
64 p_cmd->offset = AVCT_MSG_OFFSET;
65 p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
66 *p_data++ = (p_msg->hdr.ctype & AVRC_CTYPE_MASK);
67 *p_data++ = (p_msg->hdr.subunit_type << AVRC_SUBTYPE_SHIFT) | p_msg->hdr.subunit_id;
68 *p_data++ = AVRC_OP_VENDOR;
69 AVRC_CO_ID_TO_BE_STREAM(p_data, p_msg->company_id);
70 if (p_msg->vendor_len && p_msg->p_vendor_data) {
71 memcpy(p_data, p_msg->p_vendor_data, p_msg->vendor_len);
72 }
73 p_cmd->len = (UINT16) (p_data + p_msg->vendor_len - (UINT8 *)(p_cmd + 1) - p_cmd->offset);
74 p_cmd->layer_specific = AVCT_DATA_CTRL;
75 }
76 return p_cmd;
77 }
78
79 /******************************************************************************
80 **
81 ** Function AVRC_UnitCmd
82 **
83 ** Description Send a UNIT INFO command to the peer device. This
84 ** function can only be called for controller role connections.
85 ** Any response message from the peer is passed back through
86 ** the tAVRC_MSG_CBACK callback function.
87 **
88 ** Input Parameters:
89 ** handle: Handle of this connection.
90 **
91 ** label: Transaction label.
92 **
93 ** Output Parameters:
94 ** None.
95 **
96 ** Returns AVRC_SUCCESS if successful.
97 ** AVRC_BAD_HANDLE if handle is invalid.
98 **
99 ******************************************************************************/
AVRC_UnitCmd(UINT8 handle,UINT8 label)100 UINT16 AVRC_UnitCmd(UINT8 handle, UINT8 label)
101 {
102 BT_HDR *p_cmd;
103 UINT8 *p_data;
104
105 if ((p_cmd = (BT_HDR *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) {
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 *) osi_malloc(AVRC_CMD_BUF_SIZE)) != NULL) {
150 p_cmd->offset = AVCT_MSG_OFFSET;
151 p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
152 *p_data++ = AVRC_CMD_STATUS;
153 /* unit & id ignore */
154 *p_data++ = (AVRC_SUB_UNIT << AVRC_SUBTYPE_SHIFT) | AVRC_SUBID_IGNORE;
155 *p_data++ = AVRC_OP_SUB_INFO;
156 *p_data++ = ((page & AVRC_SUB_PAGE_MASK) << AVRC_SUB_PAGE_SHIFT) | AVRC_SUB_EXT_CODE;
157 memset(p_data, AVRC_CMD_OPRND_PAD, AVRC_SUB_OPRND_BYTES);
158 p_cmd->len = p_data + AVRC_SUB_OPRND_BYTES - (UINT8 *)(p_cmd + 1) - p_cmd->offset;
159 p_cmd->layer_specific = AVCT_DATA_CTRL;
160 }
161 return AVCT_MsgReq( handle, label, AVCT_CMD, p_cmd);
162 }
163
164 /******************************************************************************
165 **
166 ** Function AVRC_VendorCmd
167 **
168 ** Description Send a VENDOR DEPENDENT command to the peer device. This
169 ** function can only be called for controller role connections.
170 ** Any response message from the peer is passed back through
171 ** the tAVRC_MSG_CBACK callback function.
172 **
173 ** Input Parameters:
174 ** handle: Handle of this connection.
175 **
176 ** label: Transaction label.
177 **
178 ** p_msg: Pointer to VENDOR DEPENDENT message structure.
179 **
180 ** Output Parameters:
181 ** None.
182 **
183 ** Returns AVRC_SUCCESS if successful.
184 ** AVRC_BAD_HANDLE if handle is invalid.
185 **
186 ******************************************************************************/
AVRC_VendorCmd(UINT8 handle,UINT8 label,tAVRC_MSG_VENDOR * p_msg)187 UINT16 AVRC_VendorCmd(UINT8 handle, UINT8 label, tAVRC_MSG_VENDOR *p_msg)
188 {
189 BT_HDR *p_buf = avrc_vendor_msg(p_msg);
190 if (p_buf) {
191 return AVCT_MsgReq( handle, label, AVCT_CMD, p_buf);
192 } else {
193 return AVCT_NO_RESOURCES;
194 }
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 #endif /* #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) */
234