1 /******************************************************************************
2  *
3  *  Copyright (C) 2002-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  *  This contains constants definitions and other information from the AVDTP
22  *  specification.  This file is intended for use internal to AVDT only.
23  *
24  ******************************************************************************/
25 #ifndef AVDT_DEFS_H
26 #define AVDT_DEFS_H
27 #include "common/bt_target.h"
28 
29 #if (AVDT_INCLUDED == TRUE)
30 
31 /*****************************************************************************
32 ** constants
33 *****************************************************************************/
34 
35 /* signalling packet type */
36 #define AVDT_PKT_TYPE_SINGLE        0       /* single packet */
37 #define AVDT_PKT_TYPE_START         1       /* start packet */
38 #define AVDT_PKT_TYPE_CONT          2       /* continue packet */
39 #define AVDT_PKT_TYPE_END           3       /* end packet */
40 
41 /* signalling message type */
42 #define AVDT_MSG_TYPE_CMD           0       /* command */
43 #define AVDT_MSG_TYPE_GRJ           1       /* general reject */
44 #define AVDT_MSG_TYPE_RSP           2       /* response accept */
45 #define AVDT_MSG_TYPE_REJ           3       /* response reject */
46 
47 /* signalling messages */
48 #define AVDT_SIG_DISCOVER           1       /* discover */
49 #define AVDT_SIG_GETCAP             2       /* get capabilities */
50 #define AVDT_SIG_SETCONFIG          3       /* set configuration */
51 #define AVDT_SIG_GETCONFIG          4       /* get configuration */
52 #define AVDT_SIG_RECONFIG           5       /* reconfigure */
53 #define AVDT_SIG_OPEN               6       /* open */
54 #define AVDT_SIG_START              7       /* start */
55 #define AVDT_SIG_CLOSE              8       /* close */
56 #define AVDT_SIG_SUSPEND            9       /* suspend */
57 #define AVDT_SIG_ABORT              10      /* abort */
58 #define AVDT_SIG_SECURITY           11      /* security control */
59 #define AVDT_SIG_GET_ALLCAP         12      /* get all capabilities */
60 #define AVDT_SIG_DELAY_RPT          13      /* delay report */
61 
62 /* maximum signal value */
63 #define AVDT_SIG_MAX                AVDT_SIG_DELAY_RPT
64 
65 /* used for general reject */
66 #define AVDT_SIG_NONE               0
67 
68 /* some maximum and minimum sizes of signalling messages */
69 #define AVDT_DISCOVER_REQ_MIN       1
70 #define AVDT_DISCOVER_REQ_MAX       124
71 
72 /* service category information element field values */
73 #define AVDT_CAT_TRANS              1       /* Media Transport */
74 #define AVDT_CAT_REPORT             2       /* Reporting */
75 #define AVDT_CAT_RECOV              3       /* Recovery */
76 #define AVDT_CAT_PROTECT            4       /* Content Protection */
77 #define AVDT_CAT_HDRCMP             5       /* Header Compression */
78 #define AVDT_CAT_MUX                6       /* Multiplexing */
79 #define AVDT_CAT_CODEC              7       /* Media Codec */
80 #define AVDT_CAT_DELAY_RPT          8       /* Delay Reporting */
81 #define AVDT_CAT_MAX_CUR            AVDT_CAT_DELAY_RPT
82 
83 /* min/max lengths of service category information elements */
84 #define AVDT_LEN_TRANS_MIN          0
85 #define AVDT_LEN_REPORT_MIN         0
86 #define AVDT_LEN_RECOV_MIN          3
87 #define AVDT_LEN_PROTECT_MIN        2
88 #define AVDT_LEN_HDRCMP_MIN         1
89 #define AVDT_LEN_MUX_MIN            3
90 #define AVDT_LEN_CODEC_MIN          2
91 #define AVDT_LEN_DELAY_RPT_MIN      0
92 
93 #define AVDT_LEN_TRANS_MAX          0
94 #define AVDT_LEN_REPORT_MAX         0
95 #define AVDT_LEN_RECOV_MAX          3
96 #define AVDT_LEN_PROTECT_MAX        255
97 #define AVDT_LEN_HDRCMP_MAX         1
98 #define AVDT_LEN_MUX_MAX            7
99 #define AVDT_LEN_CODEC_MAX          255
100 #define AVDT_LEN_DELAY_RPT_MAX      0
101 
102 /* minimum possible size of configuration or capabilities data */
103 #define AVDT_LEN_CFG_MIN            2
104 
105 /* minimum and maximum lengths for different message types */
106 #define AVDT_LEN_SINGLE             1
107 #define AVDT_LEN_SETCONFIG_MIN      2
108 #define AVDT_LEN_RECONFIG_MIN       1
109 #define AVDT_LEN_MULTI_MIN          1
110 #define AVDT_LEN_SECURITY_MIN       1
111 #define AVDT_LEN_DELAY_RPT          3
112 
113 /* header lengths for different packet types */
114 #define AVDT_LEN_TYPE_SINGLE        2       /* single packet */
115 #define AVDT_LEN_TYPE_START         3       /* start packet */
116 #define AVDT_LEN_TYPE_CONT          1       /* continue packet */
117 #define AVDT_LEN_TYPE_END           1       /* end packet */
118 
119 /* length of general reject message */
120 #define AVDT_LEN_GEN_REJ            2
121 
122 /* recovery service capabilities information elements */
123 #define AVDT_RECOV_MRWS_MIN         0x01    /* min value for maximum recovery window */
124 #define AVDT_RECOV_MRWS_MAX         0x18    /* max value for maximum recovery window */
125 #define AVDT_RECOV_MNMP_MIN         0x01    /* min value for maximum number of media packets */
126 #define AVDT_RECOV_MNMP_MAX         0x18    /* max value for maximum number of media packets */
127 
128 /* SEID value range */
129 #define AVDT_SEID_MIN               0x01
130 #define AVDT_SEID_MAX               0x3E
131 
132 /* first byte of media packet header */
133 #define AVDT_MEDIA_OCTET1           0x80
134 
135 /* for adaptation layer header */
136 #define AVDT_ALH_LCODE_MASK     0x03    /* coding of length field */
137 #define AVDT_ALH_LCODE_NONE     0x00    /* No length field present. Take length from l2cap */
138 #define AVDT_ALH_LCODE_16BIT    0x01    /* 16bit length field */
139 #define AVDT_ALH_LCODE_9BITM0   0x02    /* 9 bit length field, MSB = 0, 8 LSBs in 1 octet following */
140 #define AVDT_ALH_LCODE_9BITM1   0x03    /* 9 bit length field, MSB = 1, 8 LSBs in 1 octet following */
141 
142 #define AVDT_ALH_FRAG_MASK      0x04    /* set this for continuation packet */
143 
144 /*****************************************************************************
145 ** message parsing and building macros
146 *****************************************************************************/
147 
148 #define AVDT_MSG_PRS_HDR(p, lbl, pkt, msg) \
149     lbl = *(p) >> 4; \
150     pkt = (*(p) >> 2) & 0x03; \
151     msg = *(p)++ & 0x03;
152 
153 #define AVDT_MSG_PRS_DISC(p, seid, in_use, type, tsep) \
154     seid = *(p) >> 2; \
155     in_use = (*(p)++ >> 1) & 0x01; \
156     type = *(p) >> 4; \
157     tsep = (*(p)++ >> 3) & 0x01;
158 
159 #define AVDT_MSG_PRS_SIG(p, sig) \
160     sig = *(p)++ & 0x3F;
161 
162 #define AVDT_MSG_PRS_SEID(p, seid) \
163     seid = *(p)++ >> 2;
164 
165 #define AVDT_MSG_PRS_PKT_TYPE(p, pkt) \
166     pkt = (*(p) >> 2) & 0x03;
167 
168 #define AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc) \
169     o_v = *(p) >> 6; \
170     o_p = (*(p) >> 5) & 0x01; \
171     o_x = (*(p) >> 4) & 0x01; \
172     o_cc = *(p)++ & 0x0F;
173 
174 #define AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc) \
175     o_v = *(p) >> 6; \
176     o_p = (*(p) >> 5) & 0x01; \
177     o_cc = *(p)++ & 0x1F;
178 
179 #define AVDT_MSG_PRS_M_PT(p, m_pt, marker) \
180     marker = *(p) >> 7; \
181     m_pt = *(p)++ & 0x7F;
182 
183 #define AVDT_MSG_BLD_HDR(p, lbl, pkt, msg) \
184     *(p)++ = (UINT8) ((lbl) << 4) | ((pkt) << 2) | (msg);
185 
186 #define AVDT_MSG_BLD_DISC(p, seid, in_use, type, tsep) \
187     *(p)++ = (UINT8) (((seid) << 2) | ((in_use) << 1)); \
188     *(p)++ = (UINT8) (((type) << 4) | ((tsep) << 3));
189 
190 #define AVDT_MSG_BLD_SIG(p, sig) \
191     *(p)++ = (UINT8) (sig);
192 
193 #define AVDT_MSG_BLD_SEID(p, seid) \
194     *(p)++ = (UINT8) ((seid) << 2);
195 
196 #define AVDT_MSG_BLD_ERR(p, err) \
197     *(p)++ = (UINT8) (err);
198 
199 #define AVDT_MSG_BLD_PARAM(p, param) \
200     *(p)++ = (UINT8) (param);
201 
202 #define AVDT_MSG_BLD_NOSP(p, nosp) \
203     *(p)++ = (UINT8) (nosp);
204 
205 #endif  ///AVRC_INCLUDED == TRUE
206 
207 #endif /* AVDT_DEFS_H */
208