b8c2288ca594b2f861bb3f3a72e1ade443da761c
[platform/upstream/bluez.git] / profiles / audio / avdtp.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2006-2010  Nokia Corporation
6  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
7  *
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24
25 typedef enum {
26         AVDTP_SESSION_STATE_DISCONNECTED,
27         AVDTP_SESSION_STATE_CONNECTING,
28         AVDTP_SESSION_STATE_CONNECTED
29 } avdtp_session_state_t;
30
31 struct avdtp;
32 struct avdtp_server;
33 struct avdtp_stream;
34 struct avdtp_local_sep;
35 struct avdtp_remote_sep;
36 struct avdtp_error {
37         uint8_t category;
38         union {
39                 uint8_t error_code;
40                 int posix_errno;
41         } err;
42 };
43
44 /* SEP capability categories */
45 #define AVDTP_MEDIA_TRANSPORT                   0x01
46 #define AVDTP_REPORTING                         0x02
47 #define AVDTP_RECOVERY                          0x03
48 #define AVDTP_CONTENT_PROTECTION                0x04
49 #define AVDTP_HEADER_COMPRESSION                0x05
50 #define AVDTP_MULTIPLEXING                      0x06
51 #define AVDTP_MEDIA_CODEC                       0x07
52 #define AVDTP_DELAY_REPORTING                   0x08
53 #define AVDTP_ERRNO                             0xff
54
55 /* AVDTP error definitions */
56 #define AVDTP_BAD_HEADER_FORMAT                 0x01
57 #define AVDTP_BAD_LENGTH                        0x11
58 #define AVDTP_BAD_ACP_SEID                      0x12
59 #define AVDTP_SEP_IN_USE                        0x13
60 #define AVDTP_SEP_NOT_IN_USE                    0x14
61 #define AVDTP_BAD_SERV_CATEGORY                 0x17
62 #define AVDTP_BAD_PAYLOAD_FORMAT                0x18
63 #define AVDTP_NOT_SUPPORTED_COMMAND             0x19
64 #define AVDTP_INVALID_CAPABILITIES              0x1A
65 #define AVDTP_BAD_RECOVERY_TYPE                 0x22
66 #define AVDTP_BAD_MEDIA_TRANSPORT_FORMAT        0x23
67 #define AVDTP_BAD_RECOVERY_FORMAT               0x25
68 #define AVDTP_BAD_ROHC_FORMAT                   0x26
69 #define AVDTP_BAD_CP_FORMAT                     0x27
70 #define AVDTP_BAD_MULTIPLEXING_FORMAT           0x28
71 #define AVDTP_UNSUPPORTED_CONFIGURATION         0x29
72 #define AVDTP_BAD_STATE                         0x31
73
74 /* SEP types definitions */
75 #define AVDTP_SEP_TYPE_SOURCE                   0x00
76 #define AVDTP_SEP_TYPE_SINK                     0x01
77
78 /* Media types definitions */
79 #define AVDTP_MEDIA_TYPE_AUDIO                  0x00
80 #define AVDTP_MEDIA_TYPE_VIDEO                  0x01
81 #define AVDTP_MEDIA_TYPE_MULTIMEDIA             0x02
82
83 typedef enum {
84         AVDTP_STATE_IDLE,
85         AVDTP_STATE_CONFIGURED,
86         AVDTP_STATE_OPEN,
87         AVDTP_STATE_STREAMING,
88         AVDTP_STATE_CLOSING,
89         AVDTP_STATE_ABORTING,
90 } avdtp_state_t;
91
92 struct avdtp_service_capability {
93         uint8_t category;
94         uint8_t length;
95         uint8_t data[0];
96 } __attribute__ ((packed));
97
98 #if __BYTE_ORDER == __LITTLE_ENDIAN
99
100 struct avdtp_media_codec_capability {
101         uint8_t rfa0:4;
102         uint8_t media_type:4;
103         uint8_t media_codec_type;
104         uint8_t data[0];
105 } __attribute__ ((packed));
106
107 #elif __BYTE_ORDER == __BIG_ENDIAN
108
109 struct avdtp_media_codec_capability {
110         uint8_t media_type:4;
111         uint8_t rfa0:4;
112         uint8_t media_codec_type;
113         uint8_t data[0];
114 } __attribute__ ((packed));
115
116 #else
117 #error "Unknown byte order"
118 #endif
119
120 typedef void (*avdtp_session_state_cb) (struct btd_device *dev,
121                                         struct avdtp *session,
122                                         avdtp_session_state_t old_state,
123                                         avdtp_session_state_t new_state,
124                                         void *user_data);
125
126 typedef void (*avdtp_stream_state_cb) (struct avdtp_stream *stream,
127                                         avdtp_state_t old_state,
128                                         avdtp_state_t new_state,
129                                         struct avdtp_error *err,
130                                         void *user_data);
131
132 typedef void (*avdtp_set_configuration_cb) (struct avdtp *session,
133                                                 struct avdtp_stream *stream,
134                                                 struct avdtp_error *err);
135
136 /* Callbacks for when a reply is received to a command that we sent */
137 struct avdtp_sep_cfm {
138         void (*set_configuration) (struct avdtp *session,
139                                         struct avdtp_local_sep *lsep,
140                                         struct avdtp_stream *stream,
141                                         struct avdtp_error *err,
142                                         void *user_data);
143         void (*get_configuration) (struct avdtp *session,
144                                         struct avdtp_local_sep *lsep,
145                                         struct avdtp_stream *stream,
146                                         struct avdtp_error *err,
147                                         void *user_data);
148         void (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
149                         struct avdtp_stream *stream, struct avdtp_error *err,
150                         void *user_data);
151         void (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
152                         struct avdtp_stream *stream, struct avdtp_error *err,
153                         void *user_data);
154         void (*suspend) (struct avdtp *session, struct avdtp_local_sep *lsep,
155                                 struct avdtp_stream *stream,
156                                 struct avdtp_error *err, void *user_data);
157         void (*close) (struct avdtp *session, struct avdtp_local_sep *lsep,
158                                 struct avdtp_stream *stream,
159                                 struct avdtp_error *err, void *user_data);
160         void (*abort) (struct avdtp *session, struct avdtp_local_sep *lsep,
161                                 struct avdtp_stream *stream,
162                                 struct avdtp_error *err, void *user_data);
163         void (*reconfigure) (struct avdtp *session,
164                                 struct avdtp_local_sep *lsep,
165                                 struct avdtp_stream *stream,
166                                 struct avdtp_error *err, void *user_data);
167         void (*delay_report) (struct avdtp *session, struct avdtp_local_sep *lsep,
168                                 struct avdtp_stream *stream,
169                                 struct avdtp_error *err, void *user_data);
170 };
171
172 /* Callbacks for indicating when we received a new command. The return value
173  * indicates whether the command should be rejected or accepted */
174 struct avdtp_sep_ind {
175         gboolean (*match_codec) (struct avdtp *session,
176                                 struct avdtp_media_codec_capability *codec,
177                                 void *user_data);
178         gboolean (*get_capability) (struct avdtp *session,
179                                         struct avdtp_local_sep *sep,
180                                         gboolean get_all,
181                                         GSList **caps, uint8_t *err,
182                                         void *user_data);
183         gboolean (*set_configuration) (struct avdtp *session,
184                                         struct avdtp_local_sep *lsep,
185                                         struct avdtp_stream *stream,
186                                         GSList *caps,
187                                         avdtp_set_configuration_cb cb,
188                                         void *user_data);
189         gboolean (*get_configuration) (struct avdtp *session,
190                                         struct avdtp_local_sep *lsep,
191                                         uint8_t *err, void *user_data);
192         gboolean (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
193                                 struct avdtp_stream *stream, uint8_t *err,
194                                 void *user_data);
195         gboolean (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
196                                 struct avdtp_stream *stream, uint8_t *err,
197                                 void *user_data);
198         gboolean (*suspend) (struct avdtp *session,
199                                 struct avdtp_local_sep *sep,
200                                 struct avdtp_stream *stream, uint8_t *err,
201                                 void *user_data);
202         gboolean (*close) (struct avdtp *session, struct avdtp_local_sep *sep,
203                                 struct avdtp_stream *stream, uint8_t *err,
204                                 void *user_data);
205         void (*abort) (struct avdtp *session, struct avdtp_local_sep *sep,
206                                 struct avdtp_stream *stream, uint8_t *err,
207                                 void *user_data);
208         gboolean (*reconfigure) (struct avdtp *session,
209                                         struct avdtp_local_sep *lsep,
210                                         uint8_t *err, void *user_data);
211         gboolean (*delayreport) (struct avdtp *session,
212                                         struct avdtp_local_sep *lsep,
213                                         uint8_t rseid, uint16_t delay,
214                                         uint8_t *err, void *user_data);
215 };
216
217 typedef void (*avdtp_discover_cb_t) (struct avdtp *session, GSList *seps,
218                                         struct avdtp_error *err, void *user_data);
219
220 void avdtp_unref(struct avdtp *session);
221 struct avdtp *avdtp_ref(struct avdtp *session);
222
223 struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
224                                                         void *data, int size);
225
226 struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
227                                                         uint8_t seid,
228                                                         uint8_t type,
229                                                         GSList *caps,
230                                                         bool delay_reporting);
231
232 uint8_t avdtp_get_seid(struct avdtp_remote_sep *sep);
233
234 uint8_t avdtp_get_type(struct avdtp_remote_sep *sep);
235
236 struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep);
237
238 bool avdtp_get_delay_reporting(struct avdtp_remote_sep *sep);
239
240 int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
241                         void *user_data);
242
243 gboolean avdtp_has_stream(struct avdtp *session, struct avdtp_stream *stream);
244
245 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
246 void finalize_discovery(struct avdtp *session, int err);
247 #endif
248
249 unsigned int avdtp_stream_add_cb(struct avdtp *session,
250                                         struct avdtp_stream *stream,
251                                         avdtp_stream_state_cb cb, void *data);
252 gboolean avdtp_stream_remove_cb(struct avdtp *session,
253                                 struct avdtp_stream *stream,
254                                 unsigned int id);
255
256 gboolean avdtp_stream_set_transport(struct avdtp_stream *stream, int fd,
257                                                 size_t imtu, size_t omtu);
258 gboolean avdtp_stream_get_transport(struct avdtp_stream *stream, int *sock,
259                                         uint16_t *imtu, uint16_t *omtu,
260                                         GSList **caps);
261 struct avdtp_service_capability *avdtp_stream_get_codec(
262                                                 struct avdtp_stream *stream);
263 gboolean avdtp_stream_has_capabilities(struct avdtp_stream *stream,
264                                         GSList *caps);
265 struct avdtp_remote_sep *avdtp_stream_get_remote_sep(
266                                                 struct avdtp_stream *stream);
267
268 unsigned int avdtp_add_state_cb(struct btd_device *dev,
269                                 avdtp_session_state_cb cb, void *user_data);
270
271 gboolean avdtp_remove_state_cb(unsigned int id);
272
273 int avdtp_set_configuration(struct avdtp *session,
274                                 struct avdtp_remote_sep *rsep,
275                                 struct avdtp_local_sep *lsep,
276                                 GSList *caps,
277                                 struct avdtp_stream **stream);
278
279 int avdtp_get_configuration(struct avdtp *session,
280                                 struct avdtp_stream *stream);
281
282 int avdtp_open(struct avdtp *session, struct avdtp_stream *stream);
283 int avdtp_start(struct avdtp *session, struct avdtp_stream *stream);
284 int avdtp_suspend(struct avdtp *session, struct avdtp_stream *stream);
285 int avdtp_close(struct avdtp *session, struct avdtp_stream *stream,
286                 gboolean immediate);
287 int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
288 int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
289                                                         uint16_t delay);
290 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
291 int delay_report_req(uint16_t delay);
292 #endif
293
294 struct avdtp_local_sep *avdtp_register_sep(struct queue *lseps, uint8_t type,
295                                                 uint8_t media_type,
296                                                 uint8_t codec_type,
297                                                 gboolean delay_reporting,
298                                                 struct avdtp_sep_ind *ind,
299                                                 struct avdtp_sep_cfm *cfm,
300                                                 void *user_data);
301
302 /* Find a matching pair of local and remote SEP ID's */
303 struct avdtp_remote_sep *avdtp_find_remote_sep(struct avdtp *session,
304                                                 struct avdtp_local_sep *lsep);
305
306 int avdtp_unregister_sep(struct queue *lseps, struct avdtp_local_sep *sep);
307
308 avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep);
309 uint8_t avdtp_sep_get_seid(struct avdtp_local_sep *sep);
310
311 void avdtp_error_init(struct avdtp_error *err, uint8_t type, int id);
312 const char *avdtp_strerror(struct avdtp_error *err);
313 uint8_t avdtp_error_category(struct avdtp_error *err);
314 int avdtp_error_error_code(struct avdtp_error *err);
315 int avdtp_error_posix_errno(struct avdtp_error *err);
316
317 struct btd_adapter *avdtp_get_adapter(struct avdtp *session);
318 struct btd_device *avdtp_get_device(struct avdtp *session);
319 struct avdtp_server *avdtp_get_server(struct avdtp_local_sep *lsep);
320
321 struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
322                                                         struct queue *lseps);
323 uint16_t avdtp_get_version(struct avdtp *session);
324
325 #if defined(TIZEN_FEATURE_BLUEZ_MODIFY) && defined(TIZEN_FEATURE_BLUEZ_A2DP_MULTISTREAM)
326 void avdtp_set_source_status(struct btd_device *dev, bool pause);
327 #endif