__SAMSUNG_PATCH__ --> __TIZEN_PATCH__
[framework/connectivity/bluez.git] / audio / ipc.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 /*
25   Message sequence chart of streaming sequence for A2DP transport
26
27   Audio daemon                  User
28                                 on snd_pcm_open
29                                 <--BT_GET_CAPABILITIES_REQ
30
31   BT_GET_CAPABILITIES_RSP-->
32
33                                 on snd_pcm_hw_params
34                                 <--BT_SETCONFIGURATION_REQ
35
36   BT_SET_CONFIGURATION_RSP-->
37
38                                 on snd_pcm_prepare
39                                 <--BT_START_STREAM_REQ
40
41   <Moves to streaming state>
42   BT_START_STREAM_RSP-->
43
44   BT_NEW_STREAM_IND -->
45
46                                 <  streams data >
47                                 ..........
48
49                                 on snd_pcm_drop/snd_pcm_drain
50
51                                 <--BT_STOP_STREAM_REQ
52
53   <Moves to open state>
54   BT_STOP_STREAM_RSP-->
55
56                                 on IPC close or appl crash
57   <Moves to idle>
58
59  */
60
61 #ifndef BT_AUDIOCLIENT_H
62 #define BT_AUDIOCLIENT_H
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 #include <stdint.h>
69 #include <stdio.h>
70 #include <unistd.h>
71 #include <sys/socket.h>
72 #include <sys/un.h>
73 #include <errno.h>
74
75 #define BT_SUGGESTED_BUFFER_SIZE   512
76 #define BT_IPC_SOCKET_NAME "\0/org/bluez/audio"
77
78 /* Generic message header definition, except for RESPONSE messages */
79 typedef struct {
80         uint8_t type;
81         uint8_t name;
82         uint16_t length;
83 } __attribute__ ((packed)) bt_audio_msg_header_t;
84
85 typedef struct {
86         bt_audio_msg_header_t h;
87         uint8_t posix_errno;
88 } __attribute__ ((packed)) bt_audio_error_t;
89
90 /* Message types */
91 #define BT_REQUEST                      0
92 #define BT_RESPONSE                     1
93 #define BT_INDICATION                   2
94 #define BT_ERROR                        3
95
96 /* Messages names */
97 #define BT_GET_CAPABILITIES             0
98 #define BT_OPEN                         1
99 #define BT_SET_CONFIGURATION            2
100 #define BT_NEW_STREAM                   3
101 #define BT_START_STREAM                 4
102 #define BT_STOP_STREAM                  5
103 #define BT_CLOSE                        6
104 #define BT_CONTROL                      7
105 #define BT_DELAY_REPORT                 8
106
107 #define BT_CAPABILITIES_TRANSPORT_A2DP  0
108 #define BT_CAPABILITIES_TRANSPORT_SCO   1
109 #define BT_CAPABILITIES_TRANSPORT_ANY   2
110
111 #define BT_CAPABILITIES_ACCESS_MODE_READ        1
112 #define BT_CAPABILITIES_ACCESS_MODE_WRITE       2
113 #define BT_CAPABILITIES_ACCESS_MODE_READWRITE   3
114
115 #define BT_FLAG_AUTOCONNECT     1
116
117 struct bt_get_capabilities_req {
118         bt_audio_msg_header_t   h;
119         char                    source[18];     /* Address of the local Device */
120         char                    destination[18];/* Address of the remote Device */
121         char                    object[128];    /* DBus object path */
122         uint8_t                 transport;      /* Requested transport */
123         uint8_t                 flags;          /* Requested flags */
124         uint8_t                 seid;           /* Requested capability configuration */
125 } __attribute__ ((packed));
126
127 /**
128  * SBC Codec parameters as per A2DP profile 1.0 ยง 4.3
129  */
130
131 /* A2DP seid are 6 bytes long so HSP/HFP are assigned to 7-8 bits */
132 #define BT_A2DP_SEID_RANGE                      (1 << 6) - 1
133
134 #define BT_A2DP_SBC_SOURCE                      0x00
135 #define BT_A2DP_SBC_SINK                        0x01
136 #define BT_A2DP_MPEG12_SOURCE                   0x02
137 #define BT_A2DP_MPEG12_SINK                     0x03
138 #define BT_A2DP_MPEG24_SOURCE                   0x04
139 #define BT_A2DP_MPEG24_SINK                     0x05
140 #define BT_A2DP_ATRAC_SOURCE                    0x06
141 #define BT_A2DP_ATRAC_SINK                      0x07
142 #define BT_A2DP_UNKNOWN_SOURCE                  0x08
143 #define BT_A2DP_UNKNOWN_SINK                    0x09
144
145 #define BT_SBC_SAMPLING_FREQ_16000              (1 << 3)
146 #define BT_SBC_SAMPLING_FREQ_32000              (1 << 2)
147 #define BT_SBC_SAMPLING_FREQ_44100              (1 << 1)
148 #define BT_SBC_SAMPLING_FREQ_48000              1
149
150 #define BT_A2DP_CHANNEL_MODE_MONO               (1 << 3)
151 #define BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL       (1 << 2)
152 #define BT_A2DP_CHANNEL_MODE_STEREO             (1 << 1)
153 #define BT_A2DP_CHANNEL_MODE_JOINT_STEREO       1
154
155 #define BT_A2DP_BLOCK_LENGTH_4                  (1 << 3)
156 #define BT_A2DP_BLOCK_LENGTH_8                  (1 << 2)
157 #define BT_A2DP_BLOCK_LENGTH_12                 (1 << 1)
158 #define BT_A2DP_BLOCK_LENGTH_16                 1
159
160 #define BT_A2DP_SUBBANDS_4                      (1 << 1)
161 #define BT_A2DP_SUBBANDS_8                      1
162
163 #define BT_A2DP_ALLOCATION_SNR                  (1 << 1)
164 #define BT_A2DP_ALLOCATION_LOUDNESS             1
165
166 #define BT_MPEG_SAMPLING_FREQ_16000             (1 << 5)
167 #define BT_MPEG_SAMPLING_FREQ_22050             (1 << 4)
168 #define BT_MPEG_SAMPLING_FREQ_24000             (1 << 3)
169 #define BT_MPEG_SAMPLING_FREQ_32000             (1 << 2)
170 #define BT_MPEG_SAMPLING_FREQ_44100             (1 << 1)
171 #define BT_MPEG_SAMPLING_FREQ_48000             1
172
173 #define BT_MPEG_LAYER_1                         (1 << 2)
174 #define BT_MPEG_LAYER_2                         (1 << 1)
175 #define BT_MPEG_LAYER_3                         1
176
177 #define BT_HFP_CODEC_PCM                        0x00
178
179 #define BT_PCM_FLAG_NREC                        0x01
180 #define BT_PCM_FLAG_PCM_ROUTING                 0x02
181
182 #define BT_WRITE_LOCK                           (1 << 1)
183 #define BT_READ_LOCK                            1
184
185 typedef struct {
186         uint8_t seid;
187         uint8_t transport;
188         uint8_t type;
189         uint8_t length;
190         uint8_t configured;
191         uint8_t lock;
192         uint8_t data[0];
193 } __attribute__ ((packed)) codec_capabilities_t;
194
195 typedef struct {
196         codec_capabilities_t capability;
197         uint8_t channel_mode;
198         uint8_t frequency;
199         uint8_t allocation_method;
200         uint8_t subbands;
201         uint8_t block_length;
202         uint8_t min_bitpool;
203         uint8_t max_bitpool;
204 } __attribute__ ((packed)) sbc_capabilities_t;
205
206 typedef struct {
207         codec_capabilities_t capability;
208         uint8_t channel_mode;
209         uint8_t crc;
210         uint8_t layer;
211         uint8_t frequency;
212         uint8_t mpf;
213         uint16_t bitrate;
214 } __attribute__ ((packed)) mpeg_capabilities_t;
215
216 typedef struct {
217         codec_capabilities_t capability;
218         uint8_t flags;
219         uint16_t sampling_rate;
220 } __attribute__ ((packed)) pcm_capabilities_t;
221
222 struct bt_get_capabilities_rsp {
223         bt_audio_msg_header_t   h;
224         char                    source[18];     /* Address of the local Device */
225         char                    destination[18];/* Address of the remote Device */
226         char                    object[128];    /* DBus object path */
227         uint8_t                 data[0];        /* First codec_capabilities_t */
228 } __attribute__ ((packed));
229
230 struct bt_open_req {
231         bt_audio_msg_header_t   h;
232         char                    source[18];     /* Address of the local Device */
233         char                    destination[18];/* Address of the remote Device */
234         char                    object[128];    /* DBus object path */
235         uint8_t                 seid;           /* Requested capability configuration to lock */
236         uint8_t                 lock;           /* Requested lock */
237 } __attribute__ ((packed));
238
239 struct bt_open_rsp {
240         bt_audio_msg_header_t   h;
241         char                    source[18];     /* Address of the local Device */
242         char                    destination[18];/* Address of the remote Device */
243         char                    object[128];    /* DBus object path */
244 } __attribute__ ((packed));
245
246 struct bt_set_configuration_req {
247         bt_audio_msg_header_t   h;
248         codec_capabilities_t    codec;          /* Requested codec */
249 } __attribute__ ((packed));
250
251 struct bt_set_configuration_rsp {
252         bt_audio_msg_header_t   h;
253         uint16_t                link_mtu;       /* Max length that transport supports */
254 } __attribute__ ((packed));
255
256 #define BT_STREAM_ACCESS_READ           0
257 #define BT_STREAM_ACCESS_WRITE          1
258 #define BT_STREAM_ACCESS_READWRITE      2
259 struct bt_start_stream_req {
260         bt_audio_msg_header_t   h;
261 } __attribute__ ((packed));
262
263 struct bt_start_stream_rsp {
264         bt_audio_msg_header_t   h;
265 } __attribute__ ((packed));
266
267 /* This message is followed by one byte of data containing the stream data fd
268    as ancillary data */
269 struct bt_new_stream_ind {
270         bt_audio_msg_header_t   h;
271 } __attribute__ ((packed));
272
273 struct bt_stop_stream_req {
274         bt_audio_msg_header_t   h;
275 } __attribute__ ((packed));
276
277 struct bt_stop_stream_rsp {
278         bt_audio_msg_header_t   h;
279 } __attribute__ ((packed));
280
281 struct bt_close_req {
282         bt_audio_msg_header_t   h;
283 } __attribute__ ((packed));
284
285 struct bt_close_rsp {
286         bt_audio_msg_header_t   h;
287 } __attribute__ ((packed));
288
289 struct bt_suspend_stream_ind {
290         bt_audio_msg_header_t   h;
291 } __attribute__ ((packed));
292
293 struct bt_resume_stream_ind {
294         bt_audio_msg_header_t   h;
295 } __attribute__ ((packed));
296
297 #define BT_CONTROL_KEY_POWER                    0x40
298 #define BT_CONTROL_KEY_VOL_UP                   0x41
299 #define BT_CONTROL_KEY_VOL_DOWN                 0x42
300 #define BT_CONTROL_KEY_MUTE                     0x43
301 #define BT_CONTROL_KEY_PLAY                     0x44
302 #define BT_CONTROL_KEY_STOP                     0x45
303 #define BT_CONTROL_KEY_PAUSE                    0x46
304 #define BT_CONTROL_KEY_RECORD                   0x47
305 #define BT_CONTROL_KEY_REWIND                   0x48
306 #define BT_CONTROL_KEY_FAST_FORWARD             0x49
307 #define BT_CONTROL_KEY_EJECT                    0x4A
308 #define BT_CONTROL_KEY_FORWARD                  0x4B
309 #define BT_CONTROL_KEY_BACKWARD                 0x4C
310
311 struct bt_control_req {
312         bt_audio_msg_header_t   h;
313         uint8_t                 mode;           /* Control Mode */
314         uint8_t                 key;            /* Control Key */
315 } __attribute__ ((packed));
316
317 struct bt_control_rsp {
318         bt_audio_msg_header_t   h;
319         uint8_t                 mode;           /* Control Mode */
320         uint8_t                 key;            /* Control Key */
321 } __attribute__ ((packed));
322
323 struct bt_control_ind {
324         bt_audio_msg_header_t   h;
325         uint8_t                 mode;           /* Control Mode */
326         uint8_t                 key;            /* Control Key */
327 } __attribute__ ((packed));
328
329 struct bt_delay_report_req {
330         bt_audio_msg_header_t   h;
331         uint16_t                delay;
332 } __attribute__ ((packed));
333
334 struct bt_delay_report_ind {
335         bt_audio_msg_header_t   h;
336         uint16_t                delay;
337 } __attribute__ ((packed));
338
339 /* Function declaration */
340
341 /* Opens a connection to the audio service: return a socket descriptor */
342 int bt_audio_service_open(void);
343
344 /* Closes a connection to the audio service */
345 int bt_audio_service_close(int sk);
346
347 /* Receives stream data file descriptor : must be called after a
348 BT_STREAMFD_IND message is returned */
349 int bt_audio_service_get_data_fd(int sk);
350
351 /* Human readable message type string */
352 const char *bt_audio_strtype(uint8_t type);
353
354 /* Human readable message name string */
355 const char *bt_audio_strname(uint8_t name);
356
357 #ifdef __cplusplus
358 }
359 #endif
360
361 #endif /* BT_AUDIOCLIENT_H */