1 /******************************************************************************
3 * Copyright (C) 2002-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This module contains functions for parsing and building AVDTP signaling
22 * messages. It also contains functions called by the SCB or CCB state
23 * machines for sending command, response, and reject messages. It also
24 * contains a function that processes incoming messages and dispatches them
25 * to the appropriate SCB or CCB.
27 ******************************************************************************/
31 #include "bt_target.h"
34 #include "avdtc_api.h"
36 #include "bt_common.h"
39 extern fixed_queue_t *btu_general_alarm_queue;
41 /*****************************************************************************
43 *****************************************************************************/
45 /* mask of all psc values */
46 #define AVDT_MSG_PSC_MASK (AVDT_PSC_TRANS | AVDT_PSC_REPORT | AVDT_PSC_DELAY_RPT | \
47 AVDT_PSC_RECOV | AVDT_PSC_HDRCMP | AVDT_PSC_MUX)
48 #define AVDT_PSC_PROTECT (1<<4) /* Content Protection */
49 #define AVDT_PSC_CODEC (1<<7) /* codec */
52 /*****************************************************************************
54 *****************************************************************************/
56 /* type for message building functions */
57 typedef void (*tAVDT_MSG_BLD)(UINT8 **p, tAVDT_MSG *p_msg);
59 /* type for message parsing functions */
60 typedef UINT8 (*tAVDT_MSG_PRS)(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
63 /*****************************************************************************
64 ** local function declarations
65 *****************************************************************************/
67 static void avdt_msg_bld_none(UINT8 **p, tAVDT_MSG *p_msg);
68 static void avdt_msg_bld_single(UINT8 **p, tAVDT_MSG *p_msg);
69 static void avdt_msg_bld_setconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg);
70 static void avdt_msg_bld_reconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg);
71 static void avdt_msg_bld_multi(UINT8 **p, tAVDT_MSG *p_msg);
72 static void avdt_msg_bld_security_cmd(UINT8 **p, tAVDT_MSG *p_msg);
73 static void avdt_msg_bld_discover_rsp(UINT8 **p, tAVDT_MSG *p_msg);
74 static void avdt_msg_bld_svccap(UINT8 **p, tAVDT_MSG *p_msg);
75 static void avdt_msg_bld_security_rsp(UINT8 **p, tAVDT_MSG *p_msg);
76 static void avdt_msg_bld_all_svccap(UINT8 **p, tAVDT_MSG *p_msg);
77 static void avdt_msg_bld_delay_rpt(UINT8 **p, tAVDT_MSG *p_msg);
79 static UINT8 avdt_msg_prs_none(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
80 static UINT8 avdt_msg_prs_single(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
81 static UINT8 avdt_msg_prs_setconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
82 static UINT8 avdt_msg_prs_reconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
83 static UINT8 avdt_msg_prs_multi(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
84 static UINT8 avdt_msg_prs_security_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
85 static UINT8 avdt_msg_prs_discover_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
86 static UINT8 avdt_msg_prs_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
87 static UINT8 avdt_msg_prs_all_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
88 static UINT8 avdt_msg_prs_security_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
89 static UINT8 avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, UINT8 *p, UINT16 len);
91 /*****************************************************************************
93 *****************************************************************************/
95 /* table of information element minimum lengths used for parsing */
96 const UINT8 avdt_msg_ie_len_min[] = {
98 AVDT_LEN_TRANS_MIN, /* media transport */
99 AVDT_LEN_REPORT_MIN, /* reporting */
100 AVDT_LEN_RECOV_MIN, /* recovery */
101 AVDT_LEN_PROTECT_MIN, /* content protection */
102 AVDT_LEN_HDRCMP_MIN, /* header compression */
103 AVDT_LEN_MUX_MIN, /* multiplexing */
104 AVDT_LEN_CODEC_MIN, /* codec */
105 AVDT_LEN_DELAY_RPT_MIN /* delay report */
108 /* table of information element minimum lengths used for parsing */
109 const UINT8 avdt_msg_ie_len_max[] = {
111 AVDT_LEN_TRANS_MAX, /* media transport */
112 AVDT_LEN_REPORT_MAX, /* reporting */
113 AVDT_LEN_RECOV_MAX, /* recovery */
114 AVDT_LEN_PROTECT_MAX, /* content protection */
115 AVDT_LEN_HDRCMP_MAX, /* header compression */
116 AVDT_LEN_MUX_MAX, /* multiplexing */
117 AVDT_LEN_CODEC_MAX, /* codec */
118 AVDT_LEN_DELAY_RPT_MAX /* delay report */
121 /* table of error codes used when decoding information elements */
122 const UINT8 avdt_msg_ie_err[] = {
124 AVDT_ERR_MEDIA_TRANS, /* media transport */
125 AVDT_ERR_LENGTH, /* reporting */
126 AVDT_ERR_RECOV_FMT, /* recovery */
127 AVDT_ERR_CP_FMT, /* content protection */
128 AVDT_ERR_ROHC_FMT, /* header compression */
129 AVDT_ERR_MUX_FMT, /* multiplexing */
130 AVDT_ERR_SERVICE, /* codec */
131 AVDT_ERR_SERVICE /* delay report ?? */
134 /* table of packet type minimum lengths */
135 static const UINT8 avdt_msg_pkt_type_len[] = {
136 AVDT_LEN_TYPE_SINGLE,
142 /* function table for building command messages */
143 const tAVDT_MSG_BLD avdt_msg_bld_cmd[] = {
144 avdt_msg_bld_none, /* discover */
145 avdt_msg_bld_single, /* get capabilities */
146 avdt_msg_bld_setconfig_cmd, /* set configuration */
147 avdt_msg_bld_single, /* get configuration */
148 avdt_msg_bld_reconfig_cmd, /* reconfigure */
149 avdt_msg_bld_single, /* open */
150 avdt_msg_bld_multi, /* start */
151 avdt_msg_bld_single, /* close */
152 avdt_msg_bld_multi, /* suspend */
153 avdt_msg_bld_single, /* abort */
154 avdt_msg_bld_security_cmd, /* security control */
155 avdt_msg_bld_single, /* get all capabilities */
156 avdt_msg_bld_delay_rpt /* delay report */
159 /* function table for building response messages */
160 const tAVDT_MSG_BLD avdt_msg_bld_rsp[] = {
161 avdt_msg_bld_discover_rsp, /* discover */
162 avdt_msg_bld_svccap, /* get capabilities */
163 avdt_msg_bld_none, /* set configuration */
164 avdt_msg_bld_all_svccap, /* get configuration */
165 avdt_msg_bld_none, /* reconfigure */
166 avdt_msg_bld_none, /* open */
167 avdt_msg_bld_none, /* start */
168 avdt_msg_bld_none, /* close */
169 avdt_msg_bld_none, /* suspend */
170 avdt_msg_bld_none, /* abort */
171 avdt_msg_bld_security_rsp, /* security control */
172 avdt_msg_bld_all_svccap, /* get all capabilities */
173 avdt_msg_bld_none /* delay report */
176 /* function table for parsing command messages */
177 const tAVDT_MSG_PRS avdt_msg_prs_cmd[] = {
178 avdt_msg_prs_none, /* discover */
179 avdt_msg_prs_single, /* get capabilities */
180 avdt_msg_prs_setconfig_cmd, /* set configuration */
181 avdt_msg_prs_single, /* get configuration */
182 avdt_msg_prs_reconfig_cmd, /* reconfigure */
183 avdt_msg_prs_single, /* open */
184 avdt_msg_prs_multi, /* start */
185 avdt_msg_prs_single, /* close */
186 avdt_msg_prs_multi, /* suspend */
187 avdt_msg_prs_single, /* abort */
188 avdt_msg_prs_security_cmd, /* security control */
189 avdt_msg_prs_single, /* get all capabilities */
190 avdt_msg_prs_delay_rpt /* delay report */
193 /* function table for parsing response messages */
194 const tAVDT_MSG_PRS avdt_msg_prs_rsp[] = {
195 avdt_msg_prs_discover_rsp, /* discover */
196 avdt_msg_prs_svccap, /* get capabilities */
197 avdt_msg_prs_none, /* set configuration */
198 avdt_msg_prs_all_svccap, /* get configuration */
199 avdt_msg_prs_none, /* reconfigure */
200 avdt_msg_prs_none, /* open */
201 avdt_msg_prs_none, /* start */
202 avdt_msg_prs_none, /* close */
203 avdt_msg_prs_none, /* suspend */
204 avdt_msg_prs_none, /* abort */
205 avdt_msg_prs_security_rsp, /* security control */
206 avdt_msg_prs_all_svccap, /* get all capabilities */
207 avdt_msg_prs_none /* delay report */
210 /* command message-to-event lookup table */
211 const UINT8 avdt_msg_cmd_2_evt[] = {
212 AVDT_CCB_MSG_DISCOVER_CMD_EVT + AVDT_CCB_MKR, /* discover */
213 AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get capabilities */
214 AVDT_SCB_MSG_SETCONFIG_CMD_EVT, /* set configuration */
215 AVDT_SCB_MSG_GETCONFIG_CMD_EVT, /* get configuration */
216 AVDT_SCB_MSG_RECONFIG_CMD_EVT, /* reconfigure */
217 AVDT_SCB_MSG_OPEN_CMD_EVT, /* open */
218 AVDT_CCB_MSG_START_CMD_EVT + AVDT_CCB_MKR, /* start */
219 AVDT_SCB_MSG_CLOSE_CMD_EVT, /* close */
220 AVDT_CCB_MSG_SUSPEND_CMD_EVT + AVDT_CCB_MKR, /* suspend */
221 AVDT_SCB_MSG_ABORT_CMD_EVT, /* abort */
222 AVDT_SCB_MSG_SECURITY_CMD_EVT, /* security control */
223 AVDT_CCB_MSG_GETCAP_CMD_EVT + AVDT_CCB_MKR, /* get all capabilities */
224 AVDT_SCB_MSG_DELAY_RPT_CMD_EVT /* delay report */
227 /* response message-to-event lookup table */
228 const UINT8 avdt_msg_rsp_2_evt[] = {
229 AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */
230 AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */
231 AVDT_SCB_MSG_SETCONFIG_RSP_EVT, /* set configuration */
232 AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */
233 AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */
234 AVDT_SCB_MSG_OPEN_RSP_EVT, /* open */
235 AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */
236 AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */
237 AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */
238 AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */
239 AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */
240 AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */
241 AVDT_SCB_MSG_DELAY_RPT_RSP_EVT /* delay report */
244 /* reject message-to-event lookup table */
245 const UINT8 avdt_msg_rej_2_evt[] = {
246 AVDT_CCB_MSG_DISCOVER_RSP_EVT + AVDT_CCB_MKR, /* discover */
247 AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get capabilities */
248 AVDT_SCB_MSG_SETCONFIG_REJ_EVT, /* set configuration */
249 AVDT_SCB_MSG_GETCONFIG_RSP_EVT, /* get configuration */
250 AVDT_SCB_MSG_RECONFIG_RSP_EVT, /* reconfigure */
251 AVDT_SCB_MSG_OPEN_REJ_EVT, /* open */
252 AVDT_CCB_MSG_START_RSP_EVT + AVDT_CCB_MKR, /* start */
253 AVDT_SCB_MSG_CLOSE_RSP_EVT, /* close */
254 AVDT_CCB_MSG_SUSPEND_RSP_EVT + AVDT_CCB_MKR, /* suspend */
255 AVDT_SCB_MSG_ABORT_RSP_EVT, /* abort */
256 AVDT_SCB_MSG_SECURITY_RSP_EVT, /* security control */
257 AVDT_CCB_MSG_GETCAP_RSP_EVT + AVDT_CCB_MKR, /* get all capabilities */
261 /*******************************************************************************
263 ** Function avdt_msg_bld_cfg
265 ** Description This function builds the configuration parameters contained
266 ** in a command or response message.
271 *******************************************************************************/
272 static void avdt_msg_bld_cfg(UINT8 **p, tAVDT_CFG *p_cfg)
276 /* for now, just build media transport, codec, and content protection, and multiplexing */
278 /* media transport */
279 if (p_cfg->psc_mask & AVDT_PSC_TRANS)
281 *(*p)++ = AVDT_CAT_TRANS;
282 *(*p)++ = 0; /* length */
285 #if AVDT_REPORTING == TRUE
286 /* reporting transport */
287 if (p_cfg->psc_mask & AVDT_PSC_REPORT)
289 *(*p)++ = AVDT_CAT_REPORT;
290 *(*p)++ = 0; /* length */
295 if (p_cfg->num_codec != 0)
297 *(*p)++ = AVDT_CAT_CODEC;
298 len = p_cfg->codec_info[0] + 1;
299 if( len > AVDT_CODEC_SIZE )
300 len = AVDT_CODEC_SIZE;
302 memcpy(*p, p_cfg->codec_info, len);
306 /* content protection */
307 if (p_cfg->num_protect != 0)
309 *(*p)++ = AVDT_CAT_PROTECT;
310 len = p_cfg->protect_info[0] + 1;
311 if( len > AVDT_PROTECT_SIZE )
312 len = AVDT_PROTECT_SIZE;
314 memcpy(*p, p_cfg->protect_info, len);
318 #if AVDT_MULTIPLEXING == TRUE
320 if (p_cfg->psc_mask & AVDT_PSC_MUX)
322 *(*p)++ = AVDT_CAT_MUX;
324 if (p_cfg->psc_mask & AVDT_PSC_RECOV)
325 *(*p)++ = 7; /* frag (1) + media + report + recovery */
326 else if (p_cfg->psc_mask & AVDT_PSC_REPORT)
327 *(*p)++ = 5; /* frag (1) + media + report */
329 *(*p)++ = 3; /* frag (1) + media */
331 /* allow fragmentation */
332 if(p_cfg->mux_mask & AVDT_MUX_FRAG)
337 /* media transport session */
338 *(*p)++ = p_cfg->mux_tsid_media<<3; /* TSID */
339 *(*p)++ = p_cfg->mux_tcid_media<<3; /* TCID */
341 if (p_cfg->psc_mask & AVDT_PSC_RECOV)
343 /* reporting transport session */
344 *(*p)++ = p_cfg->mux_tsid_report<<3; /* TSID */
345 *(*p)++ = p_cfg->mux_tcid_report<<3; /* TCID */
346 /* recovery transport session */
347 *(*p)++ = p_cfg->mux_tsid_recov<<3; /* TSID */
348 *(*p)++ = p_cfg->mux_tcid_recov<<3; /* TCID */
350 else if (p_cfg->psc_mask & AVDT_PSC_REPORT)
352 /* reporting transport session */
353 *(*p)++ = p_cfg->mux_tsid_report<<3; /* TSID */
354 *(*p)++ = p_cfg->mux_tcid_report<<3; /* TCID */
360 if (p_cfg->psc_mask & AVDT_PSC_DELAY_RPT)
362 *(*p)++ = AVDT_CAT_DELAY_RPT;
363 *(*p)++ = 0; /* length */
367 /*******************************************************************************
369 ** Function avdt_msg_bld_none
371 ** Description This message building function builds an empty message.
376 *******************************************************************************/
377 static void avdt_msg_bld_none(UINT8 **p, tAVDT_MSG *p_msg)
384 /*******************************************************************************
386 ** Function avdt_msg_bld_single
388 ** Description This message building function builds a message containing
394 *******************************************************************************/
395 static void avdt_msg_bld_single(UINT8 **p, tAVDT_MSG *p_msg)
397 AVDT_MSG_BLD_SEID(*p, p_msg->single.seid);
400 /*******************************************************************************
402 ** Function avdt_msg_bld_setconfig_cmd
404 ** Description This message building function builds a set configuration
410 *******************************************************************************/
411 static void avdt_msg_bld_setconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg)
413 AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.hdr.seid);
414 AVDT_MSG_BLD_SEID(*p, p_msg->config_cmd.int_seid);
415 avdt_msg_bld_cfg(p, p_msg->config_cmd.p_cfg);
418 /*******************************************************************************
420 ** Function avdt_msg_bld_reconfig_cmd
422 ** Description This message building function builds a reconfiguration
428 *******************************************************************************/
429 static void avdt_msg_bld_reconfig_cmd(UINT8 **p, tAVDT_MSG *p_msg)
431 AVDT_MSG_BLD_SEID(*p, p_msg->reconfig_cmd.hdr.seid);
433 /* force psc mask zero to build only codec and security */
434 p_msg->reconfig_cmd.p_cfg->psc_mask = 0;
435 avdt_msg_bld_cfg(p, p_msg->reconfig_cmd.p_cfg);
438 /*******************************************************************************
440 ** Function avdt_msg_bld_multi
442 ** Description This message building function builds a message containing
448 *******************************************************************************/
449 static void avdt_msg_bld_multi(UINT8 **p, tAVDT_MSG *p_msg)
453 for (i = 0; i < p_msg->multi.num_seps; i++)
455 AVDT_MSG_BLD_SEID(*p, p_msg->multi.seid_list[i]);
459 /*******************************************************************************
461 ** Function avdt_msg_bld_security_cmd
463 ** Description This message building function builds a security
468 *******************************************************************************/
469 static void avdt_msg_bld_security_cmd(UINT8 **p, tAVDT_MSG *p_msg)
471 AVDT_MSG_BLD_SEID(*p, p_msg->security_cmd.hdr.seid);
472 memcpy(*p, p_msg->security_cmd.p_data, p_msg->security_cmd.len);
473 *p += p_msg->security_cmd.len;
476 /*******************************************************************************
478 ** Function avdt_msg_bld_delay_rpt
480 ** Description This message building function builds a delay report
485 *******************************************************************************/
486 static void avdt_msg_bld_delay_rpt(UINT8 **p, tAVDT_MSG *p_msg)
488 AVDT_MSG_BLD_SEID(*p, p_msg->delay_rpt_cmd.hdr.seid);
489 UINT16_TO_BE_STREAM(*p, p_msg->delay_rpt_cmd.delay);
492 /*******************************************************************************
494 ** Function avdt_msg_bld_discover_rsp
496 ** Description This message building function builds a discover
502 *******************************************************************************/
503 static void avdt_msg_bld_discover_rsp(UINT8 **p, tAVDT_MSG *p_msg)
507 for (i = 0; i < p_msg->discover_rsp.num_seps; i++)
509 /* build discover rsp info */
510 AVDT_MSG_BLD_DISC(*p, p_msg->discover_rsp.p_sep_info[i].seid,
511 p_msg->discover_rsp.p_sep_info[i].in_use,
512 p_msg->discover_rsp.p_sep_info[i].media_type,
513 p_msg->discover_rsp.p_sep_info[i].tsep);
517 /*******************************************************************************
519 ** Function avdt_msg_bld_svccap
521 ** Description This message building function builds a message containing
522 ** service capabilities parameters.
527 *******************************************************************************/
528 static void avdt_msg_bld_svccap(UINT8 **p, tAVDT_MSG *p_msg)
532 /* make sure the delay report category is not reported */
533 memcpy (&cfg, p_msg->svccap.p_cfg, sizeof(tAVDT_CFG));
534 cfg.psc_mask &= ~AVDT_PSC_DELAY_RPT;
535 avdt_msg_bld_cfg(p, &cfg);
538 /*******************************************************************************
540 ** Function avdt_msg_bld_all_svccap
542 ** Description This message building function builds a message containing
543 ** service capabilities parameters.
548 *******************************************************************************/
549 static void avdt_msg_bld_all_svccap(UINT8 **p, tAVDT_MSG *p_msg)
551 avdt_msg_bld_cfg(p, p_msg->svccap.p_cfg);
554 /*******************************************************************************
556 ** Function avdt_msg_bld_security_rsp
558 ** Description This message building function builds a security
564 *******************************************************************************/
565 static void avdt_msg_bld_security_rsp(UINT8 **p, tAVDT_MSG *p_msg)
567 memcpy(*p, p_msg->security_rsp.p_data, p_msg->security_rsp.len);
568 *p += p_msg->security_rsp.len;
571 /*******************************************************************************
573 ** Function avdt_msg_prs_cfg
575 ** Description This message parsing function parses the configuration
576 ** parameters field of a message.
579 ** Returns Error code or zero if no error, and element that failed
582 *******************************************************************************/
583 static UINT8 avdt_msg_prs_cfg(tAVDT_CFG *p_cfg, UINT8 *p, UINT16 len, UINT8* p_elem, UINT8 sig_id)
590 UINT8 protect_offset = 0;
594 AVDT_TRACE_ERROR ("not expecting this cfg");
595 return AVDT_ERR_BAD_STATE;
599 p_cfg->num_codec = 0;
600 p_cfg->num_protect = 0;
601 #if AVDT_MULTIPLEXING == TRUE
605 /* while there is still data to parse */
607 while ((p < p_end) && (err == 0))
609 /* verify overall length */
610 if ((p_end - p) < AVDT_LEN_CFG_MIN)
612 err = AVDT_ERR_PAYLOAD;
616 /* get and verify info elem id, length */
620 if ((elem == 0) || (elem > AVDT_CAT_MAX_CUR))
622 /* this may not be really bad.
623 * It may be a service category that is too new for us.
624 * allow these to be parsed without reporting an error.
625 * If this is a "capability" (as in GetCapRsp & GetConfigRsp), this is filtered out.
626 * If this is a Configuration (as in SetConfigCmd & ReconfigCmd),
627 * this will be marked as an error in the caller of this function */
628 if ((sig_id == AVDT_SIG_SETCONFIG) || (sig_id == AVDT_SIG_RECONFIG))
630 /* Cannot accept unknown category. */
631 err = AVDT_ERR_CATEGORY;
634 else /* GETCAP or GET_ALLCAP */
636 /* Skip unknown categories. */
638 AVDT_TRACE_DEBUG("skipping unknown service category=%d len: %d", elem, elem_len);
643 if ((elem_len > avdt_msg_ie_len_max[elem]) ||
644 (elem_len < avdt_msg_ie_len_min[elem]))
646 err = avdt_msg_ie_err[elem];
650 /* add element to psc mask, but mask out codec or protect */
651 p_cfg->psc_mask |= (1 << elem);
652 AVDT_TRACE_DEBUG("elem=%d elem_len: %d psc_mask=0x%x", elem, elem_len, p_cfg->psc_mask);
654 /* parse individual information elements with additional parameters */
658 p_cfg->recov_type = *p++;
659 p_cfg->recov_mrws = *p++;
660 p_cfg->recov_mnmp = *p++;
661 if (p_cfg->recov_type != AVDT_RECOV_RFC2733)
663 err = AVDT_ERR_RECOV_TYPE;
665 else if ((p_cfg->recov_mrws < AVDT_RECOV_MRWS_MIN) ||
666 (p_cfg->recov_mrws > AVDT_RECOV_MRWS_MAX) ||
667 (p_cfg->recov_mnmp < AVDT_RECOV_MNMP_MIN) ||
668 (p_cfg->recov_mnmp > AVDT_RECOV_MNMP_MAX))
670 err = AVDT_ERR_RECOV_FMT;
674 case AVDT_CAT_PROTECT:
675 p_cfg->psc_mask &= ~AVDT_PSC_PROTECT;
676 if ((elem_len + protect_offset) < AVDT_PROTECT_SIZE)
678 p_cfg->num_protect++;
679 p_cfg->protect_info[protect_offset] = elem_len;
681 memcpy(&p_cfg->protect_info[protect_offset], p, elem_len);
682 protect_offset += elem_len;
687 case AVDT_CAT_HDRCMP:
688 p_cfg->hdrcmp_mask = *p++;
691 #if AVDT_MULTIPLEXING == TRUE
694 AVDT_TRACE_WARNING("psc_mask=0x%x elem_len=%d", p_cfg->psc_mask, elem_len);
695 if( ((0 == (p_cfg->psc_mask & (AVDT_PSC_RECOV|AVDT_PSC_REPORT))) && (elem_len != 3))
696 || (((p_cfg->psc_mask & AVDT_PSC_REPORT) && !(p_cfg->psc_mask & AVDT_PSC_RECOV))
698 || ((!(p_cfg->psc_mask & AVDT_PSC_REPORT) && (p_cfg->psc_mask & AVDT_PSC_RECOV))
700 || (((p_cfg->psc_mask & AVDT_PSC_REPORT) && (p_cfg->psc_mask & AVDT_PSC_RECOV))
701 && (elem_len != 7)) )
703 err = AVDT_ERR_MUX_FMT;
707 /* parse fragmentation */
708 p_cfg->mux_mask = *p++ & (UINT8)AVDT_MUX_FRAG;
710 /* parse TSIDs and TCIDs */
712 p_cfg->mux_tsid_media = (*p++)>>3;
717 p_cfg->mux_tcid_media = (*p++)>>3;
722 p_cfg->mux_tsid_report = (*p++)>>3;
727 p_cfg->mux_tcid_report = (*p++)>>3;
732 p_cfg->mux_tsid_recov = (*p++)>>3;
737 p_cfg->mux_tcid_recov = (*p++)>>3;
744 p_cfg->psc_mask &= ~AVDT_PSC_CODEC;
746 if (elem_len >= AVDT_CODEC_SIZE)
748 tmp = AVDT_CODEC_SIZE - 1;
751 p_cfg->codec_info[0] = elem_len;
752 memcpy(&p_cfg->codec_info[1], p, tmp);
756 case AVDT_CAT_DELAY_RPT:
763 } /* while ! err, !end*/
765 AVDT_TRACE_DEBUG("err=0x%x, elem:0x%x psc_mask=0x%x", err, elem, p_cfg->psc_mask);
770 /*******************************************************************************
772 ** Function avdt_msg_prs_none
774 ** Description This message parsing function parses a message with no parameters.
778 ** Returns Error code or zero if no error.
780 *******************************************************************************/
781 static UINT8 avdt_msg_prs_none(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
789 /*******************************************************************************
791 ** Function avdt_msg_prs_single
793 ** Description This message parsing function parses a message with a
797 ** Returns Error code or zero if no error.
799 *******************************************************************************/
800 static UINT8 avdt_msg_prs_single(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
805 if (len != AVDT_LEN_SINGLE)
807 err = AVDT_ERR_LENGTH;
811 AVDT_MSG_PRS_SEID(p, p_msg->single.seid);
813 if (avdt_scb_by_hdl(p_msg->single.seid) == NULL)
821 /*******************************************************************************
823 ** Function avdt_msg_prs_setconfig_cmd
825 ** Description This message parsing function parses a set configuration
829 ** Returns Error code or zero if no error.
831 *******************************************************************************/
832 static UINT8 avdt_msg_prs_setconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
836 p_msg->hdr.err_param = 0;
839 if (len < AVDT_LEN_SETCONFIG_MIN)
841 err = AVDT_ERR_LENGTH;
846 AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.hdr.seid);
847 if (avdt_scb_by_hdl(p_msg->config_cmd.hdr.seid) == NULL)
852 AVDT_MSG_PRS_SEID(p, p_msg->config_cmd.int_seid);
853 if ((p_msg->config_cmd.int_seid < AVDT_SEID_MIN) ||
854 (p_msg->config_cmd.int_seid > AVDT_SEID_MAX))
862 /* parse configuration parameters */
864 err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_SETCONFIG);
868 /* verify protocol service capabilities are supported */
869 if (((p_msg->config_cmd.p_cfg->psc_mask & (~AVDT_PSC)) != 0) ||
870 (p_msg->config_cmd.p_cfg->num_codec == 0))
872 err = AVDT_ERR_INVALID_CAP;
880 /*******************************************************************************
882 ** Function avdt_msg_prs_reconfig_cmd
884 ** Description This message parsing function parses a reconfiguration
888 ** Returns Error code or zero if no error.
890 *******************************************************************************/
891 static UINT8 avdt_msg_prs_reconfig_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
895 p_msg->hdr.err_param = 0;
898 if (len < AVDT_LEN_RECONFIG_MIN)
900 err = AVDT_ERR_LENGTH;
905 AVDT_MSG_PRS_SEID(p, p_msg->reconfig_cmd.hdr.seid);
906 if (avdt_scb_by_hdl(p_msg->reconfig_cmd.hdr.seid) == NULL)
912 /* parse config parameters */
914 err = avdt_msg_prs_cfg(p_msg->config_cmd.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_RECONFIG);
916 /* verify no protocol service capabilities in parameters */
919 AVDT_TRACE_DEBUG("avdt_msg_prs_reconfig_cmd psc_mask=0x%x/0x%x", p_msg->config_cmd.p_cfg->psc_mask, AVDT_MSG_PSC_MASK);
920 if ((p_msg->config_cmd.p_cfg->psc_mask != 0) ||
921 (p_msg->config_cmd.p_cfg->num_codec == 0 && p_msg->config_cmd.p_cfg->num_protect == 0))
923 err = AVDT_ERR_INVALID_CAP;
931 /*******************************************************************************
933 ** Function avdt_msg_prs_multi
935 ** Description This message parsing function parses a message containing
939 ** Returns Error code or zero if no error.
941 *******************************************************************************/
942 static UINT8 avdt_msg_prs_multi(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
947 p_msg->hdr.err_param = 0;
950 if (len < AVDT_LEN_MULTI_MIN || (len > AVDT_NUM_SEPS))
952 err = AVDT_ERR_LENGTH;
956 /* get and verify all seps */
957 for (i = 0; i < len; i++)
959 AVDT_MSG_PRS_SEID(p, p_msg->multi.seid_list[i]);
960 if (avdt_scb_by_hdl(p_msg->multi.seid_list[i]) == NULL)
963 p_msg->hdr.err_param = p_msg->multi.seid_list[i];
967 p_msg->multi.num_seps = (UINT8)i;
973 /*******************************************************************************
975 ** Function avdt_msg_prs_security_cmd
977 ** Description This message parsing function parses a security
981 ** Returns Error code or zero if no error.
983 *******************************************************************************/
984 static UINT8 avdt_msg_prs_security_cmd(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
989 if (len < AVDT_LEN_SECURITY_MIN)
991 err = AVDT_ERR_LENGTH;
996 AVDT_MSG_PRS_SEID(p, p_msg->security_cmd.hdr.seid);
997 if (avdt_scb_by_hdl(p_msg->security_cmd.hdr.seid) == NULL)
1003 p_msg->security_cmd.p_data = p;
1004 p_msg->security_cmd.len = len - 1;
1010 /*******************************************************************************
1012 ** Function avdt_msg_prs_discover_rsp
1014 ** Description This message parsing function parses a discover
1015 ** response message.
1018 ** Returns Error code or zero if no error.
1020 *******************************************************************************/
1021 static UINT8 avdt_msg_prs_discover_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
1026 /* determine number of seps; seps in msg is len/2, but set to minimum
1027 ** of seps app has supplied memory for and seps in msg
1029 if (p_msg->discover_rsp.num_seps > (len / 2))
1031 p_msg->discover_rsp.num_seps = (len / 2);
1034 /* parse out sep info */
1035 for (i = 0; i < p_msg->discover_rsp.num_seps; i++)
1037 /* parse discover rsp info */
1038 AVDT_MSG_PRS_DISC(p, p_msg->discover_rsp.p_sep_info[i].seid,
1039 p_msg->discover_rsp.p_sep_info[i].in_use,
1040 p_msg->discover_rsp.p_sep_info[i].media_type,
1041 p_msg->discover_rsp.p_sep_info[i].tsep);
1043 /* verify that seid is valid */
1044 if ((p_msg->discover_rsp.p_sep_info[i].seid < AVDT_SEID_MIN) ||
1045 (p_msg->discover_rsp.p_sep_info[i].seid > AVDT_SEID_MAX))
1047 err = AVDT_ERR_SEID;
1055 /*******************************************************************************
1057 ** Function avdt_msg_prs_svccap
1059 ** Description This message parsing function parses a message containing
1060 ** service capabilities parameters.
1063 ** Returns Error code or zero if no error.
1065 *******************************************************************************/
1066 static UINT8 avdt_msg_prs_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
1068 /* parse parameters */
1069 UINT8 err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_GETCAP);
1070 if (p_msg->svccap.p_cfg)
1072 p_msg->svccap.p_cfg->psc_mask &= AVDT_LEG_PSC;
1078 /*******************************************************************************
1080 ** Function avdt_msg_prs_all_svccap
1082 ** Description This message parsing function parses a message containing
1083 ** service capabilities parameters.
1086 ** Returns Error code or zero if no error.
1088 *******************************************************************************/
1089 static UINT8 avdt_msg_prs_all_svccap(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
1091 UINT8 err = avdt_msg_prs_cfg(p_msg->svccap.p_cfg, p, len, &p_msg->hdr.err_param, AVDT_SIG_GET_ALLCAP);
1092 if (p_msg->svccap.p_cfg)
1094 p_msg->svccap.p_cfg->psc_mask &= AVDT_MSG_PSC_MASK;
1099 /*******************************************************************************
1101 ** Function avdt_msg_prs_security_rsp
1103 ** Description This message parsing function parsing a security
1104 ** response message.
1107 ** Returns Error code or zero if no error.
1109 *******************************************************************************/
1110 static UINT8 avdt_msg_prs_security_rsp(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
1112 p_msg->security_rsp.p_data = p;
1113 p_msg->security_rsp.len = len;
1118 /*******************************************************************************
1120 ** Function avdt_msg_prs_rej
1125 ** Returns Error code or zero if no error.
1127 *******************************************************************************/
1128 static UINT8 avdt_msg_prs_rej(tAVDT_MSG *p_msg, UINT8 *p, UINT8 sig)
1130 if ((sig == AVDT_SIG_SETCONFIG) || (sig == AVDT_SIG_RECONFIG))
1132 p_msg->hdr.err_param = *p++;
1133 p_msg->hdr.err_code = *p;
1135 else if ((sig == AVDT_SIG_START) || (sig == AVDT_SIG_SUSPEND))
1137 AVDT_MSG_PRS_SEID(p, p_msg->hdr.err_param);
1138 p_msg->hdr.err_code = *p;
1142 p_msg->hdr.err_code = *p;
1148 /*******************************************************************************
1150 ** Function avdt_msg_prs_delay_rpt
1152 ** Description This message parsing function parses a security
1156 ** Returns Error code or zero if no error.
1158 *******************************************************************************/
1159 static UINT8 avdt_msg_prs_delay_rpt (tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
1164 if (len != AVDT_LEN_DELAY_RPT)
1166 AVDT_TRACE_WARNING("avdt_msg_prs_delay_rpt expected len: %u got: %u", AVDT_LEN_DELAY_RPT, len);
1167 err = AVDT_ERR_LENGTH;
1172 AVDT_MSG_PRS_SEID (p, p_msg->delay_rpt_cmd.hdr.seid);
1174 if (avdt_scb_by_hdl(p_msg->delay_rpt_cmd.hdr.seid) == NULL)
1176 err = AVDT_ERR_SEID;
1180 BE_STREAM_TO_UINT16 (p_msg->delay_rpt_cmd.delay, p);
1181 AVDT_TRACE_DEBUG("avdt_msg_prs_delay_rpt delay: %u", p_msg->delay_rpt_cmd.delay);
1188 /*******************************************************************************
1190 ** Function avdt_msg_send
1192 ** Description Send, and if necessary fragment the next message.
1195 ** Returns Congested state; TRUE if CCB congested, FALSE if not.
1197 *******************************************************************************/
1198 BOOLEAN avdt_msg_send(tAVDT_CCB *p_ccb, BT_HDR *p_msg)
1200 UINT16 curr_msg_len;
1203 tAVDT_TC_TBL *p_tbl;
1209 UINT8 nosp = 0; /* number of subsequent packets */
1211 /* look up transport channel table entry to get peer mtu */
1212 p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_SIG, p_ccb, NULL);
1214 /* set the current message if there is a message passed in */
1217 p_ccb->p_curr_msg = p_msg;
1220 /* store copy of curr_msg->len */
1221 curr_msg_len = p_ccb->p_curr_msg->len;
1223 /* while not congested and we haven't sent it all */
1224 while ((!p_ccb->cong) && (p_ccb->p_curr_msg != NULL))
1226 /* check what kind of message we've got here; we are using the offset
1227 ** to indicate that a message is being fragmented
1230 /* if message isn't being fragmented and it fits in mtu */
1231 if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) &&
1232 (p_ccb->p_curr_msg->len <= p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE))
1234 pkt_type = AVDT_PKT_TYPE_SINGLE;
1235 hdr_len = AVDT_LEN_TYPE_SINGLE;
1236 p_buf = p_ccb->p_curr_msg;
1238 /* if message isn't being fragmented and it doesn't fit in mtu */
1239 else if ((p_ccb->p_curr_msg->offset == AVDT_MSG_OFFSET) &&
1240 (p_ccb->p_curr_msg->len > p_tbl->peer_mtu - AVDT_LEN_TYPE_SINGLE))
1242 pkt_type = AVDT_PKT_TYPE_START;
1243 hdr_len = AVDT_LEN_TYPE_START;
1244 nosp = (p_ccb->p_curr_msg->len + AVDT_LEN_TYPE_START - p_tbl->peer_mtu) /
1245 (p_tbl->peer_mtu - 1) + 2;
1247 /* get a new buffer for fragment we are sending */
1248 p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
1250 /* copy portion of data from current message to new buffer */
1251 p_buf->offset = L2CAP_MIN_OFFSET + hdr_len;
1252 p_buf->len = p_tbl->peer_mtu - hdr_len;
1253 memcpy((UINT8 *)(p_buf + 1) + p_buf->offset,
1254 (UINT8 *)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, p_buf->len);
1256 /* if message is being fragmented and remaining bytes don't fit in mtu */
1257 else if ((p_ccb->p_curr_msg->offset > AVDT_MSG_OFFSET) &&
1258 (p_ccb->p_curr_msg->len > (p_tbl->peer_mtu - AVDT_LEN_TYPE_CONT)))
1260 pkt_type = AVDT_PKT_TYPE_CONT;
1261 hdr_len = AVDT_LEN_TYPE_CONT;
1263 /* get a new buffer for fragment we are sending */
1264 p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
1266 /* copy portion of data from current message to new buffer */
1267 p_buf->offset = L2CAP_MIN_OFFSET + hdr_len;
1268 p_buf->len = p_tbl->peer_mtu - hdr_len;
1269 memcpy((UINT8 *)(p_buf + 1) + p_buf->offset,
1270 (UINT8 *)(p_ccb->p_curr_msg + 1) + p_ccb->p_curr_msg->offset, p_buf->len);
1272 /* if message is being fragmented and remaining bytes do fit in mtu */
1275 pkt_type = AVDT_PKT_TYPE_END;
1276 hdr_len = AVDT_LEN_TYPE_END;
1277 p_buf = p_ccb->p_curr_msg;
1280 /* label, sig id, msg type are in hdr of p_curr_msg */
1281 label = AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_msg->layer_specific);
1282 msg = AVDT_LAYERSPEC_MSG(p_ccb->p_curr_msg->layer_specific);
1283 sig = (UINT8) p_ccb->p_curr_msg->event;
1284 AVDT_TRACE_DEBUG("avdt_msg_send label:%d, msg:%d, sig:%d", label, msg, sig);
1286 /* keep track of how much of msg we've sent */
1287 curr_msg_len -= p_buf->len;
1288 if (curr_msg_len == 0)
1290 /* entire message sent; mark as finished */
1291 p_ccb->p_curr_msg = NULL;
1293 /* start timer here for commands */
1294 if (msg == AVDT_MSG_TYPE_CMD)
1296 /* if retransmit timeout set to zero, sig doesn't use retransmit */
1297 if ((sig == AVDT_SIG_DISCOVER) || (sig == AVDT_SIG_GETCAP) ||
1298 (sig == AVDT_SIG_SECURITY) || (avdt_cb.rcb.ret_tout == 0))
1300 alarm_cancel(p_ccb->idle_ccb_timer);
1301 alarm_cancel(p_ccb->ret_ccb_timer);
1302 period_ms_t interval_ms = avdt_cb.rcb.sig_tout * 1000;
1303 alarm_set_on_queue(p_ccb->rsp_ccb_timer, interval_ms,
1304 avdt_ccb_rsp_ccb_timer_timeout, p_ccb,
1305 btu_general_alarm_queue);
1307 else if (sig != AVDT_SIG_DELAY_RPT)
1309 alarm_cancel(p_ccb->idle_ccb_timer);
1310 alarm_cancel(p_ccb->rsp_ccb_timer);
1311 period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000;
1312 alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms,
1313 avdt_ccb_ret_ccb_timer_timeout, p_ccb,
1314 btu_general_alarm_queue);
1320 /* message being fragmented and not completely sent */
1321 p_ccb->p_curr_msg->len -= p_buf->len;
1322 p_ccb->p_curr_msg->offset += p_buf->len;
1325 /* set up to build header */
1326 p_buf->len += hdr_len;
1327 p_buf->offset -= hdr_len;
1328 p = (UINT8 *)(p_buf + 1) + p_buf->offset;
1331 AVDT_MSG_BLD_HDR(p, label, pkt_type, msg);
1332 if (pkt_type == AVDT_PKT_TYPE_START)
1334 AVDT_MSG_BLD_NOSP(p, nosp);
1336 if ((pkt_type == AVDT_PKT_TYPE_START) || (pkt_type == AVDT_PKT_TYPE_SINGLE))
1338 AVDT_MSG_BLD_SIG(p, sig);
1341 /* send msg buffer down */
1342 avdt_ad_write_req(AVDT_CHAN_SIG, p_ccb, NULL, p_buf);
1344 return (p_ccb->cong);
1347 /*******************************************************************************
1349 ** Function avdt_msg_asmbl
1351 ** Description Reassemble incoming message.
1354 ** Returns Pointer to reassembled message; NULL if no message
1357 *******************************************************************************/
1358 BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
1364 /* parse the message header */
1365 p = (UINT8 *)(p_buf + 1) + p_buf->offset;
1366 AVDT_MSG_PRS_PKT_TYPE(p, pkt_type);
1368 /* quick sanity check on length */
1369 if (p_buf->len < avdt_msg_pkt_type_len[pkt_type])
1372 AVDT_TRACE_WARNING("Bad length during reassembly");
1376 else if (pkt_type == AVDT_PKT_TYPE_SINGLE)
1378 /* if reassembly in progress drop message and process new single */
1379 if (p_ccb->p_rx_msg != NULL)
1380 AVDT_TRACE_WARNING("Got single during reassembly");
1382 osi_free_and_reset((void **)&p_ccb->p_rx_msg);
1387 else if (pkt_type == AVDT_PKT_TYPE_START)
1389 /* if reassembly in progress drop message and process new single */
1390 if (p_ccb->p_rx_msg != NULL)
1391 AVDT_TRACE_WARNING("Got start during reassembly");
1393 osi_free_and_reset((void **)&p_ccb->p_rx_msg);
1396 * Allocate bigger buffer for reassembly. As lower layers are
1397 * not aware of possible packet size after reassembly, they
1398 * would have allocated smaller buffer.
1400 p_ccb->p_rx_msg = (BT_HDR *)osi_malloc(BT_DEFAULT_BUFFER_SIZE);
1401 memcpy(p_ccb->p_rx_msg, p_buf,
1402 sizeof(BT_HDR) + p_buf->offset + p_buf->len);
1404 /* Free original buffer */
1407 /* update p to point to new buffer */
1408 p = (UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset;
1410 /* copy first header byte over nosp */
1413 /* set offset to point to where to copy next */
1414 p_ccb->p_rx_msg->offset += p_ccb->p_rx_msg->len;
1416 /* adjust length for packet header */
1417 p_ccb->p_rx_msg->len -= 1;
1421 /* continue or end */
1424 /* if no reassembly in progress drop message */
1425 if (p_ccb->p_rx_msg == NULL)
1428 AVDT_TRACE_WARNING("Pkt type=%d out of order", pkt_type);
1433 /* get size of buffer holding assembled message */
1435 * NOTE: The buffer is allocated above at the beginning of the
1436 * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE.
1438 UINT16 buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR);
1440 /* adjust offset and len of fragment for header byte */
1441 p_buf->offset += AVDT_LEN_TYPE_CONT;
1442 p_buf->len -= AVDT_LEN_TYPE_CONT;
1445 if ((p_ccb->p_rx_msg->offset + p_buf->len) > buf_len) {
1446 /* won't fit; free everything */
1447 AVDT_TRACE_WARNING("%s: Fragmented message too big!", __func__);
1448 osi_free_and_reset((void **)&p_ccb->p_rx_msg);
1452 /* copy contents of p_buf to p_rx_msg */
1453 memcpy((UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset,
1454 (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
1456 if (pkt_type == AVDT_PKT_TYPE_END)
1458 p_ccb->p_rx_msg->offset -= p_ccb->p_rx_msg->len;
1459 p_ccb->p_rx_msg->len += p_buf->len;
1460 p_ret = p_ccb->p_rx_msg;
1461 p_ccb->p_rx_msg = NULL;
1465 p_ccb->p_rx_msg->offset += p_buf->len;
1466 p_ccb->p_rx_msg->len += p_buf->len;
1476 /*******************************************************************************
1478 ** Function avdt_msg_send_cmd
1480 ** Description This function is called to send a command message. The
1481 ** sig_id parameter indicates the message type, p_params
1482 ** points to the message parameters, if any. It gets a buffer
1483 ** from the AVDTP command pool, executes the message building
1484 ** function for this message type. It then queues the message
1485 ** in the command queue for this CCB.
1490 *******************************************************************************/
1491 void avdt_msg_send_cmd(tAVDT_CCB *p_ccb, void *p_scb, UINT8 sig_id, tAVDT_MSG *p_params)
1495 BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
1497 /* set up buf pointer and offset */
1498 p_buf->offset = AVDT_MSG_OFFSET;
1499 p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
1501 /* execute parameter building function to build message */
1502 (*avdt_msg_bld_cmd[sig_id - 1])(&p, p_params);
1505 p_buf->len = (UINT16) (p - p_start);
1507 /* now store scb hdls, if any, in buf */
1510 p = (UINT8 *)(p_buf + 1);
1512 /* for start and suspend, p_scb points to array of handles */
1513 if ((sig_id == AVDT_SIG_START) || (sig_id == AVDT_SIG_SUSPEND))
1515 memcpy(p, (UINT8 *) p_scb, p_buf->len);
1517 /* for all others, p_scb points to scb as usual */
1520 *p = avdt_scb_to_hdl((tAVDT_SCB *) p_scb);
1524 /* stash sig, label, and message type in buf */
1525 p_buf->event = sig_id;
1526 AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_CMD, p_ccb->label);
1528 /* increment label */
1529 p_ccb->label = (p_ccb->label + 1) % 16;
1531 /* queue message and trigger ccb to send it */
1532 fixed_queue_enqueue(p_ccb->cmd_q, p_buf);
1533 avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
1537 /*******************************************************************************
1539 ** Function avdt_msg_send_rsp
1541 ** Description This function is called to send a response message. The
1542 ** sig_id parameter indicates the message type, p_params
1543 ** points to the message parameters, if any. It gets a buffer
1544 ** from the AVDTP command pool, executes the message building
1545 ** function for this message type. It then queues the message
1546 ** in the response queue for this CCB.
1551 *******************************************************************************/
1552 void avdt_msg_send_rsp(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
1556 BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
1558 /* set up buf pointer and offset */
1559 p_buf->offset = AVDT_MSG_OFFSET;
1560 p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
1562 /* execute parameter building function to build message */
1563 (*avdt_msg_bld_rsp[sig_id - 1])(&p, p_params);
1566 p_buf->len = (UINT16) (p - p_start);
1568 /* stash sig, label, and message type in buf */
1569 p_buf->event = sig_id;
1570 AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_RSP, p_params->hdr.label);
1572 /* queue message and trigger ccb to send it */
1573 fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
1574 avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
1578 /*******************************************************************************
1580 ** Function avdt_msg_send_rej
1582 ** Description This function is called to send a reject message. The
1583 ** sig_id parameter indicates the message type. It gets
1584 ** a buffer from the AVDTP command pool and builds the
1585 ** message based on the message type and the error code.
1586 ** It then queues the message in the response queue for
1592 *******************************************************************************/
1593 void avdt_msg_send_rej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
1597 BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
1599 /* set up buf pointer and offset */
1600 p_buf->offset = AVDT_MSG_OFFSET;
1601 p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
1603 /* if sig id included, build into message */
1604 if (sig_id != AVDT_SIG_NONE)
1606 /* if this sig has a parameter, add the parameter */
1607 if ((sig_id == AVDT_SIG_SETCONFIG) ||
1608 (sig_id == AVDT_SIG_RECONFIG))
1610 AVDT_MSG_BLD_PARAM(p, p_params->hdr.err_param);
1612 else if ((sig_id == AVDT_SIG_START) ||
1613 (sig_id == AVDT_SIG_SUSPEND))
1615 AVDT_MSG_BLD_SEID(p, p_params->hdr.err_param);
1618 /* add the error code */
1619 AVDT_MSG_BLD_ERR(p, p_params->hdr.err_code);
1621 AVDT_TRACE_DEBUG("avdt_msg_send_rej");
1623 /* calculate length */
1624 p_buf->len = (UINT16) (p - p_start);
1626 /* stash sig, label, and message type in buf */
1627 p_buf->event = sig_id;
1628 AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_REJ, p_params->hdr.label);
1630 /* queue message and trigger ccb to send it */
1631 fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
1632 avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
1635 /*******************************************************************************
1637 ** Function avdt_msg_send_grej
1639 ** Description This function is called to send a general reject message. The
1640 ** sig_id parameter indicates the message type. It gets
1641 ** a buffer from the AVDTP command pool and builds the
1642 ** message based on the message type and the error code.
1643 ** It then queues the message in the response queue for
1649 *******************************************************************************/
1650 void avdt_msg_send_grej(tAVDT_CCB *p_ccb, UINT8 sig_id, tAVDT_MSG *p_params)
1654 BT_HDR *p_buf = (BT_HDR *)osi_malloc(AVDT_CMD_BUF_SIZE);
1656 /* set up buf pointer and offset */
1657 p_buf->offset = AVDT_MSG_OFFSET;
1658 p_start = p = (UINT8 *)(p_buf + 1) + p_buf->offset;
1660 /* calculate length */
1661 p_buf->len = (UINT16) (p - p_start);
1663 /* stash sig, label, and message type in buf */
1665 AVDT_BLD_LAYERSPEC(p_buf->layer_specific, 0, p_params->hdr.label);
1666 AVDT_TRACE_DEBUG("avdt_msg_send_grej");
1668 /* queue message and trigger ccb to send it */
1669 fixed_queue_enqueue(p_ccb->rsp_q, p_buf);
1670 avdt_ccb_event(p_ccb, AVDT_CCB_SENDMSG_EVT, NULL);
1673 /*******************************************************************************
1675 ** Function avdt_msg_ind
1677 ** Description This function is called by the adaption layer when an
1678 ** incoming message is received on the signaling channel.
1679 ** It parses the message and sends an event to the appropriate
1680 ** SCB or CCB for the message.
1685 *******************************************************************************/
1686 void avdt_msg_ind(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
1691 BOOLEAN handle_rsp = FALSE;
1692 BOOLEAN gen_rej = FALSE;
1703 /* reassemble message; if no message available (we received a fragment) return */
1704 if ((p_buf = avdt_msg_asmbl(p_ccb, p_buf)) == NULL)
1709 p = (UINT8 *)(p_buf + 1) + p_buf->offset;
1711 /* parse the message header */
1712 AVDT_MSG_PRS_HDR(p, label, pkt_type, msg_type);
1716 AVDT_TRACE_DEBUG("msg_type=%d, sig=%d", msg_type, sig);
1717 /* set up label and ccb_idx in message hdr */
1718 msg.hdr.label = label;
1719 msg.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb);
1721 /* verify msg type */
1722 if (msg_type == AVDT_MSG_TYPE_GRJ)
1724 AVDT_TRACE_WARNING("Dropping msg msg_type=%d", msg_type);
1727 /* check for general reject */
1728 else if ((msg_type == AVDT_MSG_TYPE_REJ) && (p_buf->len == AVDT_LEN_GEN_REJ))
1731 if (p_ccb->p_curr_cmd != NULL)
1733 msg.hdr.sig_id = sig = (UINT8) p_ccb->p_curr_cmd->event;
1734 evt = avdt_msg_rej_2_evt[sig - 1];
1735 msg.hdr.err_code = AVDT_ERR_NSC;
1736 msg.hdr.err_param = 0;
1739 else /* not a general reject */
1741 /* get and verify signal */
1742 AVDT_MSG_PRS_SIG(p, sig);
1743 msg.hdr.sig_id = sig;
1744 if ((sig == 0) || (sig > AVDT_SIG_MAX))
1746 AVDT_TRACE_WARNING("Dropping msg sig=%d msg_type:%d", sig, msg_type);
1749 /* send a general reject */
1750 if (msg_type == AVDT_MSG_TYPE_CMD)
1752 avdt_msg_send_grej(p_ccb, sig, &msg);
1759 /* skip over header (msg length already verified during reassembly) */
1760 p_buf->len -= AVDT_LEN_TYPE_SINGLE;
1762 /* set up to parse message */
1763 if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_DISCOVER))
1765 /* parse discover rsp message to struct supplied by app */
1766 msg.discover_rsp.p_sep_info = (tAVDT_SEP_INFO *) p_ccb->p_proc_data;
1767 msg.discover_rsp.num_seps = p_ccb->proc_param;
1769 else if ((msg_type == AVDT_MSG_TYPE_RSP) &&
1770 ((sig == AVDT_SIG_GETCAP) || (sig == AVDT_SIG_GET_ALLCAP)))
1772 /* parse discover rsp message to struct supplied by app */
1773 msg.svccap.p_cfg = (tAVDT_CFG *) p_ccb->p_proc_data;
1775 else if ((msg_type == AVDT_MSG_TYPE_RSP) && (sig == AVDT_SIG_GETCONFIG))
1777 /* parse get config rsp message to struct allocated locally */
1778 msg.svccap.p_cfg = &cfg;
1780 else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_SETCONFIG))
1782 /* parse config cmd message to struct allocated locally */
1783 msg.config_cmd.p_cfg = &cfg;
1785 else if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig == AVDT_SIG_RECONFIG))
1787 /* parse reconfig cmd message to struct allocated locally */
1788 msg.reconfig_cmd.p_cfg = &cfg;
1791 /* parse message; while we're at it map message sig to event */
1792 if (msg_type == AVDT_MSG_TYPE_CMD)
1794 msg.hdr.err_code = err = (*avdt_msg_prs_cmd[sig - 1])(&msg, p, p_buf->len);
1795 evt = avdt_msg_cmd_2_evt[sig - 1];
1797 else if (msg_type == AVDT_MSG_TYPE_RSP)
1799 msg.hdr.err_code = err = (*avdt_msg_prs_rsp[sig - 1])(&msg, p, p_buf->len);
1800 evt = avdt_msg_rsp_2_evt[sig - 1];
1802 else /* msg_type == AVDT_MSG_TYPE_REJ */
1804 err = avdt_msg_prs_rej(&msg, p, sig);
1805 evt = avdt_msg_rej_2_evt[sig - 1];
1808 /* if parsing failed */
1811 AVDT_TRACE_WARNING("Parsing failed sig=%d err=0x%x", sig, err);
1813 /* if its a rsp or rej, drop it; if its a cmd, send a rej;
1814 ** note special case for abort; never send abort reject
1817 if ((msg_type == AVDT_MSG_TYPE_CMD) && (sig != AVDT_SIG_ABORT))
1819 avdt_msg_send_rej(p_ccb, sig, &msg);
1824 /* if its a rsp or rej, check sent cmd to see if we're waiting for
1825 ** the rsp or rej. If we didn't send a cmd for it, drop it. If
1826 ** it does match a cmd, stop timer for the cmd.
1830 if ((msg_type == AVDT_MSG_TYPE_RSP) || (msg_type == AVDT_MSG_TYPE_REJ))
1832 if ((p_ccb->p_curr_cmd != NULL) &&
1833 (p_ccb->p_curr_cmd->event == sig) &&
1834 (AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_cmd->layer_specific) == label))
1837 alarm_cancel(p_ccb->idle_ccb_timer);
1838 alarm_cancel(p_ccb->ret_ccb_timer);
1839 alarm_cancel(p_ccb->rsp_ccb_timer);
1841 /* clear retransmission count */
1842 p_ccb->ret_count = 0;
1844 /* later in this function handle ccb event */
1850 AVDT_TRACE_WARNING("Cmd not found for rsp sig=%d label=%d", sig, label);
1857 /* if it's a ccb event send to ccb */
1858 if (evt & AVDT_CCB_MKR)
1860 avdt_ccb_event(p_ccb, (UINT8)(evt & ~AVDT_CCB_MKR), (tAVDT_CCB_EVT *) &msg);
1862 /* if it's a scb event */
1865 /* Scb events always have a single seid. For cmd, get seid from
1866 ** message. For rej and rsp, get seid from p_curr_cmd.
1868 if (msg_type == AVDT_MSG_TYPE_CMD)
1870 scb_hdl = msg.single.seid;
1874 scb_hdl = *((UINT8 *)(p_ccb->p_curr_cmd + 1));
1877 /* Map seid to the scb and send it the event. For cmd, seid has
1878 ** already been verified by parsing function.
1880 if (evt && (p_scb = avdt_scb_by_hdl(scb_hdl)) != NULL)
1882 avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT *) &msg);
1887 /* free message buffer */
1890 /* if its a rsp or rej, send event to ccb to free associated
1891 ** cmd msg buffer and handle cmd queue
1895 avdt_ccb_event(p_ccb, AVDT_CCB_RCVRSP_EVT, NULL);