1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
24
25
26
27
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
144
145
146
147
148
149
150
151
152
153
154
155
156
157
160
161
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
279
280
287
288
289
290
291
295
299
302
303
304
308
312
315
318
319
320
324
325
326
327
328
329
/* ... */
#include <string.h>
#include "common/bt_target.h"
#include "stack/avrc_api.h"
#include "stack/avrc_defs.h"
#include "avrc_int.h"
#include "osi/allocator.h"6 includes
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
/* ... */
#if (AVRC_METADATA_INCLUDED == TRUE)
/* ... */
static tAVRC_STS avrc_bld_next_cmd (tAVRC_NEXT_CMD *p_cmd, BT_HDR *p_pkt)
{
UINT8 *p_data, *p_start;
AVRC_TRACE_API("avrc_bld_next_cmd");
p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
p_data = p_start + 2;
UINT16_TO_BE_STREAM(p_data, 1);
UINT8_TO_BE_STREAM(p_data, p_cmd->target_pdu);
p_pkt->len = (p_data - p_start);
return AVRC_STS_NO_ERROR;
}{...}
/* ... */
#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
/* ... */
static tAVRC_STS avrc_bld_set_abs_volume_cmd (tAVRC_SET_VOLUME_CMD *p_cmd, BT_HDR *p_pkt)
{
UINT8 *p_data, *p_start;
AVRC_TRACE_API("avrc_bld_set_abs_volume_cmd");
p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
p_data = p_start + 2;
UINT16_TO_BE_STREAM(p_data, 1);
UINT8_TO_BE_STREAM(p_data, (AVRC_MAX_VOLUME & p_cmd->volume));
p_pkt->len = (p_data - p_start);
return AVRC_STS_NO_ERROR;
}{...}
/* ... */
static tAVRC_STS avrc_bld_register_change_notfn(UINT8 event_id, UINT32 event_parameter, BT_HDR *p_pkt)
{
UINT8 *p_data, *p_start;
AVRC_TRACE_API("avrc_bld_vol_change");
p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
p_data = p_start + 2;
UINT16_TO_BE_STREAM(p_data, 5);
UINT8_TO_BE_STREAM(p_data, event_id);
UINT32_TO_BE_STREAM(p_data, event_parameter);
p_pkt->len = (p_data - p_start);
return AVRC_STS_NO_ERROR;
}{...}
/* ... */#endif
/* ... */
static BT_HDR *avrc_bld_init_cmd_buffer(tAVRC_COMMAND *p_cmd)
{
UINT8 opcode = avrc_opcode_from_pdu(p_cmd->pdu);
AVRC_TRACE_API("avrc_bld_init_cmd_buffer: pdu=%x, opcode=%x", p_cmd->pdu, opcode);
UINT16 offset = 0;
switch (opcode) {
case AVRC_OP_PASS_THRU:
offset = AVRC_MSG_PASS_THRU_OFFSET;
break;
...
case AVRC_OP_VENDOR:
offset = AVRC_MSG_VENDOR_OFFSET;
break;...
}{...}
BT_HDR *p_pkt = (BT_HDR *)osi_malloc(AVRC_META_CMD_BUF_SIZE);
if (p_pkt) {
UINT8 *p_data, *p_start;
p_pkt->layer_specific = AVCT_DATA_CTRL;
p_pkt->event = opcode;
p_pkt->offset = offset;
p_data = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
p_start = p_data;
if (opcode != AVRC_OP_PASS_THRU) {
*p_data++ = p_cmd->pdu;
}{...}
switch (opcode) {
case AVRC_OP_VENDOR:
UINT8_TO_BE_STREAM(p_data, 0);
UINT16_TO_BE_STREAM(p_data, 0);
break;...
}{...}
p_pkt->len = (p_data - p_start);
}{...}
p_cmd->cmd.opcode = opcode;
return p_pkt;
}{...}
/* ... */
static tAVRC_STS avrc_bld_set_player_value_cmd(tAVRC_SET_APP_VALUE_CMD *p_cmd, BT_HDR *p_pkt)
{
UINT8 *p_data, *p_start;
p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
p_data = p_start + 2;
UINT16_TO_BE_STREAM(p_data, 3);
UINT8_TO_BE_STREAM(p_data, 1);
UINT8_TO_BE_STREAM(p_data, p_cmd->p_vals->attr_id);
UINT8_TO_BE_STREAM(p_data, p_cmd->p_vals->attr_val);
p_pkt->len = (p_data - p_start);
return AVRC_STS_NO_ERROR;
}{...}
/* ... */
static tAVRC_STS avrc_bld_get_element_attr_cmd (tAVRC_GET_ELEM_ATTRS_CMD *p_cmd, BT_HDR *p_pkt)
{
int i;
UINT8 *p_data, *p_start;
AVRC_TRACE_API("avrc_bld_get_element_attr_cmd num_attr: %d", p_cmd->num_attr);
p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
p_data = p_start + 2;
UINT16_TO_BE_STREAM(p_data, 8 + 1 + p_cmd->num_attr * sizeof(UINT32));
UINT64_TO_BE_STREAM(p_data, (UINT64)(0));
UINT8_TO_BE_STREAM(p_data, p_cmd->num_attr);
for (i = 0; i < p_cmd->num_attr; i++) {
AVRC_TRACE_API("avrc_bld_get_element_attr_cmd attr_id: %d", p_cmd->attrs[i]);
UINT32_TO_BE_STREAM(p_data, p_cmd->attrs[i]);
}{...}
p_pkt->len = (p_data - p_start);
return AVRC_STS_NO_ERROR;
}{...}
static tAVRC_STS avrc_bld_get_caps_cmd(tAVRC_GET_CAPS_CMD *p_cmd, BT_HDR *p_pkt)
{
UINT8 *p_data, *p_start;
AVRC_TRACE_API("avrc_bld_get_caps");
p_start = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
p_data = p_start + 2;
UINT16_TO_BE_STREAM(p_data, 1);
UINT8_TO_BE_STREAM(p_data, p_cmd->capability_id);
p_pkt->len = (p_data - p_start);
return AVRC_STS_NO_ERROR;
}{...}
/* ... */
tAVRC_STS AVRC_BldCommand( tAVRC_COMMAND *p_cmd, BT_HDR **pp_pkt)
{
tAVRC_STS status = AVRC_STS_BAD_PARAM;
BT_HDR *p_pkt;
BOOLEAN alloc = FALSE;
AVRC_TRACE_API("AVRC_BldCommand: pdu=%x status=%x", p_cmd->cmd.pdu, p_cmd->cmd.status);
if (!p_cmd || !pp_pkt) {
AVRC_TRACE_API("AVRC_BldCommand. Invalid parameters passed. p_cmd=%p, pp_pkt=%p",
p_cmd, pp_pkt);
return AVRC_STS_BAD_PARAM;
}{...}
if (*pp_pkt == NULL) {
if ((*pp_pkt = avrc_bld_init_cmd_buffer(p_cmd)) == NULL) {
AVRC_TRACE_API("AVRC_BldCommand: Failed to initialize command buffer");
return AVRC_STS_INTERNAL_ERR;
}{...}
alloc = TRUE;
}{...}
status = AVRC_STS_NO_ERROR;
p_pkt = *pp_pkt;
switch (p_cmd->pdu) {
case AVRC_PDU_REQUEST_CONTINUATION_RSP:
status = avrc_bld_next_cmd(&p_cmd->continu, p_pkt);
break;
...
case AVRC_PDU_ABORT_CONTINUATION_RSP:
status = avrc_bld_next_cmd(&p_cmd->abort, p_pkt);
break;
#if (AVRC_ADV_CTRL_INCLUDED == TRUE)...
case AVRC_PDU_SET_ABSOLUTE_VOLUME:
status = avrc_bld_set_abs_volume_cmd(&p_cmd->volume, p_pkt);
break;/* ... */
#endif
case AVRC_PDU_SET_PLAYER_APP_VALUE:
status = avrc_bld_set_player_value_cmd(&p_cmd->set_app_val, p_pkt);
break;
...
case AVRC_PDU_GET_ELEMENT_ATTR:
status = avrc_bld_get_element_attr_cmd(&p_cmd->get_elem_attrs, p_pkt);
break;
...
case AVRC_PDU_REGISTER_NOTIFICATION:
status = avrc_bld_register_change_notfn(p_cmd->reg_notif.event_id, p_cmd->reg_notif.param, p_pkt);
break;...
case AVRC_PDU_GET_CAPABILITIES:
status = avrc_bld_get_caps_cmd(&p_cmd->get_caps, p_pkt);
break;...
}{...}
if (alloc && (status != AVRC_STS_NO_ERROR) ) {
osi_free(p_pkt);
*pp_pkt = NULL;
}{...}
AVRC_TRACE_API("AVRC_BldCommand: returning %d", status);
return status;
}{...}
/* ... */#endif
/* ... */
#endif