3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
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.
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.
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
24 Message sequence chart of streaming sequence for A2DP transport
28 <--BT_GET_CAPABILITIES_REQ
30 BT_GET_CAPABILITIES_RSP-->
33 <--BT_SETCONFIGURATION_REQ
35 BT_SET_CONFIGURATION_RSP-->
38 <--BT_START_STREAM_REQ
40 <Moves to streaming state>
41 BT_START_STREAM_RSP-->
48 on snd_pcm_drop/snd_pcm_drain
55 on IPC close or appl crash
60 #ifndef BT_AUDIOCLIENT_H
61 #define BT_AUDIOCLIENT_H
70 #include <sys/socket.h>
74 #define BT_SUGGESTED_BUFFER_SIZE 512
75 #define BT_IPC_SOCKET_NAME "\0/org/bluez/audio"
77 /* Generic message header definition, except for RESPONSE messages */
82 } __attribute__ ((packed)) bt_audio_msg_header_t;
85 bt_audio_msg_header_t h;
87 } __attribute__ ((packed)) bt_audio_error_t;
92 #define BT_INDICATION 2
96 #define BT_GET_CAPABILITIES 0
98 #define BT_SET_CONFIGURATION 2
99 #define BT_NEW_STREAM 3
100 #define BT_START_STREAM 4
101 #define BT_STOP_STREAM 5
104 #define BT_DELAY_REPORT 8
106 #define BT_CAPABILITIES_TRANSPORT_A2DP 0
107 #define BT_CAPABILITIES_TRANSPORT_SCO 1
108 #define BT_CAPABILITIES_TRANSPORT_ANY 2
110 #define BT_CAPABILITIES_ACCESS_MODE_READ 1
111 #define BT_CAPABILITIES_ACCESS_MODE_WRITE 2
112 #define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3
114 #define BT_FLAG_AUTOCONNECT 1
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));
127 * SBC Codec parameters as per A2DP profile 1.0 ยง 4.3
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
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
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
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
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
159 #define BT_A2DP_SUBBANDS_4 (1 << 1)
160 #define BT_A2DP_SUBBANDS_8 1
162 #define BT_A2DP_ALLOCATION_SNR (1 << 1)
163 #define BT_A2DP_ALLOCATION_LOUDNESS 1
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
172 #define BT_MPEG_LAYER_1 (1 << 2)
173 #define BT_MPEG_LAYER_2 (1 << 1)
174 #define BT_MPEG_LAYER_3 1
176 #define BT_HFP_CODEC_PCM 0x00
178 #define BT_PCM_FLAG_NREC 0x01
179 #define BT_PCM_FLAG_PCM_ROUTING 0x02
181 #define BT_WRITE_LOCK (1 << 1)
182 #define BT_READ_LOCK 1
192 } __attribute__ ((packed)) codec_capabilities_t;
195 codec_capabilities_t capability;
196 uint8_t channel_mode;
198 uint8_t allocation_method;
200 uint8_t block_length;
203 } __attribute__ ((packed)) sbc_capabilities_t;
206 codec_capabilities_t capability;
207 uint8_t channel_mode;
213 } __attribute__ ((packed)) mpeg_capabilities_t;
216 codec_capabilities_t capability;
218 uint16_t sampling_rate;
219 } __attribute__ ((packed)) pcm_capabilities_t;
221 struct bt_get_capabilities_rsp {
222 bt_audio_msg_header_t h;
223 char source[18]; /* Address of the local Device */
224 char destination[18];/* Address of the remote Device */
225 char object[128]; /* DBus object path */
226 uint8_t data[0]; /* First codec_capabilities_t */
227 } __attribute__ ((packed));
230 bt_audio_msg_header_t h;
231 char source[18]; /* Address of the local Device */
232 char destination[18];/* Address of the remote Device */
233 char object[128]; /* DBus object path */
234 uint8_t seid; /* Requested capability configuration to lock */
235 uint8_t lock; /* Requested lock */
236 } __attribute__ ((packed));
239 bt_audio_msg_header_t h;
240 char source[18]; /* Address of the local Device */
241 char destination[18];/* Address of the remote Device */
242 char object[128]; /* DBus object path */
243 } __attribute__ ((packed));
245 struct bt_set_configuration_req {
246 bt_audio_msg_header_t h;
247 codec_capabilities_t codec; /* Requested codec */
248 } __attribute__ ((packed));
250 struct bt_set_configuration_rsp {
251 bt_audio_msg_header_t h;
252 uint16_t link_mtu; /* Max length that transport supports */
253 } __attribute__ ((packed));
255 #define BT_STREAM_ACCESS_READ 0
256 #define BT_STREAM_ACCESS_WRITE 1
257 #define BT_STREAM_ACCESS_READWRITE 2
258 struct bt_start_stream_req {
259 bt_audio_msg_header_t h;
260 } __attribute__ ((packed));
262 struct bt_start_stream_rsp {
263 bt_audio_msg_header_t h;
264 } __attribute__ ((packed));
266 /* This message is followed by one byte of data containing the stream data fd
267 as ancilliary data */
268 struct bt_new_stream_ind {
269 bt_audio_msg_header_t h;
270 } __attribute__ ((packed));
272 struct bt_stop_stream_req {
273 bt_audio_msg_header_t h;
274 } __attribute__ ((packed));
276 struct bt_stop_stream_rsp {
277 bt_audio_msg_header_t h;
278 } __attribute__ ((packed));
280 struct bt_close_req {
281 bt_audio_msg_header_t h;
282 } __attribute__ ((packed));
284 struct bt_close_rsp {
285 bt_audio_msg_header_t h;
286 } __attribute__ ((packed));
288 struct bt_suspend_stream_ind {
289 bt_audio_msg_header_t h;
290 } __attribute__ ((packed));
292 struct bt_resume_stream_ind {
293 bt_audio_msg_header_t h;
294 } __attribute__ ((packed));
296 #define BT_CONTROL_KEY_POWER 0x40
297 #define BT_CONTROL_KEY_VOL_UP 0x41
298 #define BT_CONTROL_KEY_VOL_DOWN 0x42
299 #define BT_CONTROL_KEY_MUTE 0x43
300 #define BT_CONTROL_KEY_PLAY 0x44
301 #define BT_CONTROL_KEY_STOP 0x45
302 #define BT_CONTROL_KEY_PAUSE 0x46
303 #define BT_CONTROL_KEY_RECORD 0x47
304 #define BT_CONTROL_KEY_REWIND 0x48
305 #define BT_CONTROL_KEY_FAST_FORWARD 0x49
306 #define BT_CONTROL_KEY_EJECT 0x4A
307 #define BT_CONTROL_KEY_FORWARD 0x4B
308 #define BT_CONTROL_KEY_BACKWARD 0x4C
310 struct bt_control_req {
311 bt_audio_msg_header_t h;
312 uint8_t mode; /* Control Mode */
313 uint8_t key; /* Control Key */
314 } __attribute__ ((packed));
316 struct bt_control_rsp {
317 bt_audio_msg_header_t h;
318 uint8_t mode; /* Control Mode */
319 uint8_t key; /* Control Key */
320 } __attribute__ ((packed));
322 struct bt_control_ind {
323 bt_audio_msg_header_t h;
324 uint8_t mode; /* Control Mode */
325 uint8_t key; /* Control Key */
326 } __attribute__ ((packed));
328 struct bt_delay_report_req {
329 bt_audio_msg_header_t h;
331 } __attribute__ ((packed));
333 struct bt_delay_report_ind {
334 bt_audio_msg_header_t h;
336 } __attribute__ ((packed));
338 /* Function declaration */
340 /* Opens a connection to the audio service: return a socket descriptor */
341 int bt_audio_service_open(void);
343 /* Closes a connection to the audio service */
344 int bt_audio_service_close(int sk);
346 /* Receives stream data file descriptor : must be called after a
347 BT_STREAMFD_IND message is returned */
348 int bt_audio_service_get_data_fd(int sk);
350 /* Human readable message type string */
351 const char *bt_audio_strtype(uint8_t type);
353 /* Human readable message name string */
354 const char *bt_audio_strname(uint8_t name);
360 #endif /* BT_AUDIOCLIENT_H */