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