tizen 2.3.1 release
[framework/connectivity/bluez.git] / android / 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 struct avdtp;
26 struct avdtp_stream;
27 struct avdtp_local_sep;
28 struct avdtp_remote_sep;
29 struct avdtp_error {
30         uint8_t category;
31         union {
32                 uint8_t error_code;
33                 int posix_errno;
34         } err;
35 };
36
37 #define AVDTP_PSM 25
38
39 /* SEP capability categories */
40 #define AVDTP_MEDIA_TRANSPORT                   0x01
41 #define AVDTP_REPORTING                         0x02
42 #define AVDTP_RECOVERY                          0x03
43 #define AVDTP_CONTENT_PROTECTION                0x04
44 #define AVDTP_HEADER_COMPRESSION                0x05
45 #define AVDTP_MULTIPLEXING                      0x06
46 #define AVDTP_MEDIA_CODEC                       0x07
47 #define AVDTP_DELAY_REPORTING                   0x08
48 #define AVDTP_ERRNO                             0xff
49
50 /* AVDTP error definitions */
51 #define AVDTP_BAD_HEADER_FORMAT                 0x01
52 #define AVDTP_BAD_LENGTH                        0x11
53 #define AVDTP_BAD_ACP_SEID                      0x12
54 #define AVDTP_SEP_IN_USE                        0x13
55 #define AVDTP_SEP_NOT_IN_USE                    0x14
56 #define AVDTP_BAD_SERV_CATEGORY                 0x17
57 #define AVDTP_BAD_PAYLOAD_FORMAT                0x18
58 #define AVDTP_NOT_SUPPORTED_COMMAND             0x19
59 #define AVDTP_INVALID_CAPABILITIES              0x1A
60 #define AVDTP_BAD_RECOVERY_TYPE                 0x22
61 #define AVDTP_BAD_MEDIA_TRANSPORT_FORMAT        0x23
62 #define AVDTP_BAD_RECOVERY_FORMAT               0x25
63 #define AVDTP_BAD_ROHC_FORMAT                   0x26
64 #define AVDTP_BAD_CP_FORMAT                     0x27
65 #define AVDTP_BAD_MULTIPLEXING_FORMAT           0x28
66 #define AVDTP_UNSUPPORTED_CONFIGURATION         0x29
67 #define AVDTP_BAD_STATE                         0x31
68
69 /* SEP types definitions */
70 #define AVDTP_SEP_TYPE_SOURCE                   0x00
71 #define AVDTP_SEP_TYPE_SINK                     0x01
72
73 /* Media types definitions */
74 #define AVDTP_MEDIA_TYPE_AUDIO                  0x00
75 #define AVDTP_MEDIA_TYPE_VIDEO                  0x01
76 #define AVDTP_MEDIA_TYPE_MULTIMEDIA             0x02
77
78 typedef enum {
79         AVDTP_STATE_IDLE,
80         AVDTP_STATE_CONFIGURED,
81         AVDTP_STATE_OPEN,
82         AVDTP_STATE_STREAMING,
83         AVDTP_STATE_CLOSING,
84         AVDTP_STATE_ABORTING,
85 } avdtp_state_t;
86
87 struct avdtp_service_capability {
88         uint8_t category;
89         uint8_t length;
90         uint8_t data[0];
91 } __attribute__ ((packed));
92
93 #if __BYTE_ORDER == __LITTLE_ENDIAN
94
95 struct avdtp_media_codec_capability {
96         uint8_t rfa0:4;
97         uint8_t media_type:4;
98         uint8_t media_codec_type;
99         uint8_t data[0];
100 } __attribute__ ((packed));
101
102 #elif __BYTE_ORDER == __BIG_ENDIAN
103
104 struct avdtp_media_codec_capability {
105         uint8_t media_type:4;
106         uint8_t rfa0:4;
107         uint8_t media_codec_type;
108         uint8_t data[0];
109 } __attribute__ ((packed));
110
111 #else
112 #error "Unknown byte order"
113 #endif
114
115 typedef void (*avdtp_stream_state_cb) (struct avdtp_stream *stream,
116                                         avdtp_state_t old_state,
117                                         avdtp_state_t new_state,
118                                         struct avdtp_error *err,
119                                         void *user_data);
120
121 typedef void (*avdtp_set_configuration_cb) (struct avdtp *session,
122                                                 struct avdtp_stream *stream,
123                                                 struct avdtp_error *err);
124
125 /* Callbacks for when a reply is received to a command that we sent */
126 struct avdtp_sep_cfm {
127         void (*set_configuration) (struct avdtp *session,
128                                         struct avdtp_local_sep *lsep,
129                                         struct avdtp_stream *stream,
130                                         struct avdtp_error *err,
131                                         void *user_data);
132         void (*get_configuration) (struct avdtp *session,
133                                         struct avdtp_local_sep *lsep,
134                                         struct avdtp_stream *stream,
135                                         struct avdtp_error *err,
136                                         void *user_data);
137         void (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
138                         struct avdtp_stream *stream, struct avdtp_error *err,
139                         void *user_data);
140         void (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
141                         struct avdtp_stream *stream, struct avdtp_error *err,
142                         void *user_data);
143         void (*suspend) (struct avdtp *session, struct avdtp_local_sep *lsep,
144                                 struct avdtp_stream *stream,
145                                 struct avdtp_error *err, void *user_data);
146         void (*close) (struct avdtp *session, struct avdtp_local_sep *lsep,
147                                 struct avdtp_stream *stream,
148                                 struct avdtp_error *err, void *user_data);
149         void (*abort) (struct avdtp *session, struct avdtp_local_sep *lsep,
150                                 struct avdtp_stream *stream,
151                                 struct avdtp_error *err, void *user_data);
152         void (*reconfigure) (struct avdtp *session,
153                                 struct avdtp_local_sep *lsep,
154                                 struct avdtp_stream *stream,
155                                 struct avdtp_error *err, void *user_data);
156         void (*delay_report) (struct avdtp *session, struct avdtp_local_sep *lsep,
157                                 struct avdtp_stream *stream,
158                                 struct avdtp_error *err, void *user_data);
159 };
160
161 /*
162  * Callbacks for indicating when we received a new command. The return value
163  * indicates whether the command should be rejected or accepted
164  */
165 struct avdtp_sep_ind {
166         gboolean (*get_capability) (struct avdtp *session,
167                                         struct avdtp_local_sep *sep,
168                                         GSList **caps, uint8_t *err,
169                                         void *user_data);
170         gboolean (*set_configuration) (struct avdtp *session,
171                                         struct avdtp_local_sep *lsep,
172                                         struct avdtp_stream *stream,
173                                         GSList *caps,
174                                         avdtp_set_configuration_cb cb,
175                                         void *user_data);
176         gboolean (*get_configuration) (struct avdtp *session,
177                                         struct avdtp_local_sep *lsep,
178                                         uint8_t *err, void *user_data);
179         gboolean (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
180                                 struct avdtp_stream *stream, uint8_t *err,
181                                 void *user_data);
182         gboolean (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
183                                 struct avdtp_stream *stream, uint8_t *err,
184                                 void *user_data);
185         gboolean (*suspend) (struct avdtp *session,
186                                 struct avdtp_local_sep *sep,
187                                 struct avdtp_stream *stream, uint8_t *err,
188                                 void *user_data);
189         gboolean (*close) (struct avdtp *session, struct avdtp_local_sep *sep,
190                                 struct avdtp_stream *stream, uint8_t *err,
191                                 void *user_data);
192         void (*abort) (struct avdtp *session, struct avdtp_local_sep *sep,
193                                 struct avdtp_stream *stream, uint8_t *err,
194                                 void *user_data);
195         gboolean (*reconfigure) (struct avdtp *session,
196                                         struct avdtp_local_sep *lsep,
197                                         uint8_t *err, void *user_data);
198         gboolean (*delayreport) (struct avdtp *session,
199                                         struct avdtp_local_sep *lsep,
200                                         uint8_t rseid, uint16_t delay,
201                                         uint8_t *err, void *user_data);
202 };
203
204 typedef void (*avdtp_discover_cb_t) (struct avdtp *session, GSList *seps,
205                                         struct avdtp_error *err, void *user_data);
206 typedef void (*avdtp_disconnect_cb_t) (void *user_data);
207
208 struct avdtp *avdtp_new(int fd, size_t imtu, size_t omtu, uint16_t version,
209                                                         struct queue *lseps);
210
211 unsigned int avdtp_add_disconnect_cb(struct avdtp *session,
212                                                 avdtp_disconnect_cb_t cb,
213                                                 void *user_data);
214 gboolean avdtp_remove_disconnect_cb(struct avdtp *session, unsigned int id);
215
216 void avdtp_shutdown(struct avdtp *session);
217
218 void avdtp_unref(struct avdtp *session);
219 struct avdtp *avdtp_ref(struct avdtp *session);
220
221 struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
222                                                         const void *data,
223                                                         int size);
224
225 struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep);
226
227 int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
228                         void *user_data);
229
230 gboolean avdtp_has_stream(struct avdtp *session, struct avdtp_stream *stream);
231
232 unsigned int avdtp_stream_add_cb(struct avdtp *session,
233                                         struct avdtp_stream *stream,
234                                         avdtp_stream_state_cb cb, void *data);
235 gboolean avdtp_stream_remove_cb(struct avdtp *session,
236                                 struct avdtp_stream *stream,
237                                 unsigned int id);
238
239 gboolean avdtp_stream_set_transport(struct avdtp_stream *stream, int fd,
240                                                 size_t imtu, size_t omtu);
241 gboolean avdtp_stream_get_transport(struct avdtp_stream *stream, int *sock,
242                                         uint16_t *imtu, uint16_t *omtu,
243                                         GSList **caps);
244 struct avdtp_service_capability *avdtp_stream_get_codec(
245                                                 struct avdtp_stream *stream);
246 gboolean avdtp_stream_has_capabilities(struct avdtp_stream *stream,
247                                         GSList *caps);
248 struct avdtp_remote_sep *avdtp_stream_get_remote_sep(
249                                                 struct avdtp_stream *stream);
250
251 int avdtp_set_configuration(struct avdtp *session,
252                                 struct avdtp_remote_sep *rsep,
253                                 struct avdtp_local_sep *lsep,
254                                 GSList *caps,
255                                 struct avdtp_stream **stream);
256
257 int avdtp_get_configuration(struct avdtp *session,
258                                 struct avdtp_stream *stream);
259
260 int avdtp_open(struct avdtp *session, struct avdtp_stream *stream);
261 int avdtp_start(struct avdtp *session, struct avdtp_stream *stream);
262 int avdtp_suspend(struct avdtp *session, struct avdtp_stream *stream);
263 int avdtp_close(struct avdtp *session, struct avdtp_stream *stream,
264                 gboolean immediate);
265 int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
266 int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
267                                                         uint16_t delay);
268
269 struct avdtp_local_sep *avdtp_register_sep(struct queue *lseps, uint8_t type,
270                                                 uint8_t media_type,
271                                                 uint8_t codec_type,
272                                                 gboolean delay_reporting,
273                                                 struct avdtp_sep_ind *ind,
274                                                 struct avdtp_sep_cfm *cfm,
275                                                 void *user_data);
276 void avdtp_sep_set_vendor_codec(struct avdtp_local_sep *sep, uint32_t vendor_id,
277                                                         uint16_t codec_id);
278
279 /* Find a matching pair of local and remote SEP ID's */
280 struct avdtp_remote_sep *avdtp_find_remote_sep(struct avdtp *session,
281                                                 struct avdtp_local_sep *lsep);
282
283 int avdtp_unregister_sep(struct queue *lseps, struct avdtp_local_sep *sep);
284
285 avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep);
286
287 void avdtp_error_init(struct avdtp_error *err, uint8_t type, int id);
288 const char *avdtp_strerror(struct avdtp_error *err);
289 uint8_t avdtp_error_category(struct avdtp_error *err);
290 int avdtp_error_error_code(struct avdtp_error *err);
291 int avdtp_error_posix_errno(struct avdtp_error *err);