3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
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.
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.
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
25 Message sequence chart of streaming sequence for A2DP transport
29 <--BT_GET_CAPABILITIES_REQ
31 BT_GET_CAPABILITIES_RSP-->
34 <--BT_SETCONFIGURATION_REQ
36 BT_SET_CONFIGURATION_RSP-->
39 <--BT_START_STREAM_REQ
41 <Moves to streaming state>
42 BT_START_STREAM_RSP-->
49 on snd_pcm_drop/snd_pcm_drain
56 on IPC close or appl crash
61 #ifndef BT_AUDIOCLIENT_H
62 #define BT_AUDIOCLIENT_H
71 #include <sys/socket.h>
75 #define BT_SUGGESTED_BUFFER_SIZE 512
76 #define BT_IPC_SOCKET_NAME "\0/org/bluez/audio"
78 /* Generic message header definition, except for RESPONSE messages */
83 } __attribute__ ((packed)) bt_audio_msg_header_t;
86 bt_audio_msg_header_t h;
88 } __attribute__ ((packed)) bt_audio_error_t;
93 #define BT_INDICATION 2
97 #define BT_GET_CAPABILITIES 0
99 #define BT_SET_CONFIGURATION 2
100 #define BT_NEW_STREAM 3
101 #define BT_START_STREAM 4
102 #define BT_STOP_STREAM 5
105 #define BT_DELAY_REPORT 8
107 #define BT_CAPABILITIES_TRANSPORT_A2DP 0
108 #define BT_CAPABILITIES_TRANSPORT_SCO 1
109 #define BT_CAPABILITIES_TRANSPORT_ANY 2
111 #define BT_CAPABILITIES_ACCESS_MODE_READ 1
112 #define BT_CAPABILITIES_ACCESS_MODE_WRITE 2
113 #define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3
115 #define BT_FLAG_AUTOCONNECT 1
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));
128 * SBC Codec parameters as per A2DP profile 1.0 ยง 4.3
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
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
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
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
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
160 #define BT_A2DP_SUBBANDS_4 (1 << 1)
161 #define BT_A2DP_SUBBANDS_8 1
163 #define BT_A2DP_ALLOCATION_SNR (1 << 1)
164 #define BT_A2DP_ALLOCATION_LOUDNESS 1
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
173 #define BT_MPEG_LAYER_1 (1 << 2)
174 #define BT_MPEG_LAYER_2 (1 << 1)
175 #define BT_MPEG_LAYER_3 1
177 #define BT_HFP_CODEC_PCM 0x00
179 #define BT_PCM_FLAG_NREC 0x01
180 #define BT_PCM_FLAG_PCM_ROUTING 0x02
182 #define BT_WRITE_LOCK (1 << 1)
183 #define BT_READ_LOCK 1
193 } __attribute__ ((packed)) codec_capabilities_t;
196 codec_capabilities_t capability;
197 uint8_t channel_mode;
199 uint8_t allocation_method;
201 uint8_t block_length;
204 } __attribute__ ((packed)) sbc_capabilities_t;
207 codec_capabilities_t capability;
208 uint8_t channel_mode;
214 } __attribute__ ((packed)) mpeg_capabilities_t;
217 codec_capabilities_t capability;
219 uint16_t sampling_rate;
220 } __attribute__ ((packed)) pcm_capabilities_t;
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));
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));
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));
246 struct bt_set_configuration_req {
247 bt_audio_msg_header_t h;
248 codec_capabilities_t codec; /* Requested codec */
249 } __attribute__ ((packed));
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));
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));
263 struct bt_start_stream_rsp {
264 bt_audio_msg_header_t h;
265 } __attribute__ ((packed));
267 /* This message is followed by one byte of data containing the stream data fd
269 struct bt_new_stream_ind {
270 bt_audio_msg_header_t h;
271 } __attribute__ ((packed));
273 struct bt_stop_stream_req {
274 bt_audio_msg_header_t h;
275 } __attribute__ ((packed));
277 struct bt_stop_stream_rsp {
278 bt_audio_msg_header_t h;
279 } __attribute__ ((packed));
281 struct bt_close_req {
282 bt_audio_msg_header_t h;
283 } __attribute__ ((packed));
285 struct bt_close_rsp {
286 bt_audio_msg_header_t h;
287 } __attribute__ ((packed));
289 struct bt_suspend_stream_ind {
290 bt_audio_msg_header_t h;
291 } __attribute__ ((packed));
293 struct bt_resume_stream_ind {
294 bt_audio_msg_header_t h;
295 } __attribute__ ((packed));
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
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));
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));
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));
329 struct bt_delay_report_req {
330 bt_audio_msg_header_t h;
332 } __attribute__ ((packed));
334 struct bt_delay_report_ind {
335 bt_audio_msg_header_t h;
337 } __attribute__ ((packed));
339 /* Function declaration */
341 /* Opens a connection to the audio service: return a socket descriptor */
342 int bt_audio_service_open(void);
344 /* Closes a connection to the audio service */
345 int bt_audio_service_close(int sk);
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);
351 /* Human readable message type string */
352 const char *bt_audio_strtype(uint8_t type);
354 /* Human readable message name string */
355 const char *bt_audio_strname(uint8_t name);
361 #endif /* BT_AUDIOCLIENT_H */