3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2008 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 128
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
97 #define BT_SET_CONFIGURATION 1
98 #define BT_NEW_STREAM 2
99 #define BT_START_STREAM 3
100 #define BT_STOP_STREAM 4
101 #define BT_SUSPEND_STREAM 5
102 #define BT_RESUME_STREAM 6
105 #define BT_CAPABILITIES_TRANSPORT_A2DP 0
106 #define BT_CAPABILITIES_TRANSPORT_SCO 1
107 #define BT_CAPABILITIES_TRANSPORT_ANY 2
109 #define BT_CAPABILITIES_ACCESS_MODE_READ 1
110 #define BT_CAPABILITIES_ACCESS_MODE_WRITE 2
111 #define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3
113 #define BT_FLAG_AUTOCONNECT 1
115 struct bt_get_capabilities_req
{
116 bt_audio_msg_header_t h
;
117 char device
[18]; /* Address of the remote Device */
118 uint8_t transport
; /* Requested transport */
119 uint8_t flags
; /* Requested flags */
120 } __attribute__ ((packed
));
123 * SBC Codec parameters as per A2DP profile 1.0 ยง 4.3
126 #define BT_A2DP_CODEC_SBC 0x00
127 #define BT_A2DP_CODEC_MPEG12 0x01
128 #define BT_A2DP_CODEC_MPEG24 0x02
129 #define BT_A2DP_CODEC_ATRAC 0x03
131 #define BT_SBC_SAMPLING_FREQ_16000 (1 << 3)
132 #define BT_SBC_SAMPLING_FREQ_32000 (1 << 2)
133 #define BT_SBC_SAMPLING_FREQ_44100 (1 << 1)
134 #define BT_SBC_SAMPLING_FREQ_48000 1
136 #define BT_A2DP_CHANNEL_MODE_MONO (1 << 3)
137 #define BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
138 #define BT_A2DP_CHANNEL_MODE_STEREO (1 << 1)
139 #define BT_A2DP_CHANNEL_MODE_JOINT_STEREO 1
141 #define BT_A2DP_BLOCK_LENGTH_4 (1 << 3)
142 #define BT_A2DP_BLOCK_LENGTH_8 (1 << 2)
143 #define BT_A2DP_BLOCK_LENGTH_12 (1 << 1)
144 #define BT_A2DP_BLOCK_LENGTH_16 1
146 #define BT_A2DP_SUBBANDS_4 (1 << 1)
147 #define BT_A2DP_SUBBANDS_8 1
149 #define BT_A2DP_ALLOCATION_SNR (1 << 1)
150 #define BT_A2DP_ALLOCATION_LOUDNESS 1
152 #define BT_MPEG_SAMPLING_FREQ_16000 (1 << 5)
153 #define BT_MPEG_SAMPLING_FREQ_22050 (1 << 4)
154 #define BT_MPEG_SAMPLING_FREQ_24000 (1 << 3)
155 #define BT_MPEG_SAMPLING_FREQ_32000 (1 << 2)
156 #define BT_MPEG_SAMPLING_FREQ_44100 (1 << 1)
157 #define BT_MPEG_SAMPLING_FREQ_48000 1
159 #define BT_MPEG_LAYER_1 (1 << 2)
160 #define BT_MPEG_LAYER_2 (1 << 1)
161 #define BT_MPEG_LAYER_3 1
163 #define BT_HFP_CODEC_PCM 0x00
165 #define BT_PCM_FLAG_NREC 1
172 } __attribute__ ((packed
)) codec_capabilities_t
;
175 codec_capabilities_t capability
;
176 uint8_t channel_mode
;
178 uint8_t allocation_method
;
180 uint8_t block_length
;
183 } __attribute__ ((packed
)) sbc_capabilities_t
;
186 codec_capabilities_t capability
;
187 uint8_t channel_mode
;
193 } __attribute__ ((packed
)) mpeg_capabilities_t
;
196 codec_capabilities_t capability
;
198 uint16_t sampling_rate
;
199 } __attribute__ ((packed
)) pcm_capabilities_t
;
202 struct bt_get_capabilities_rsp
{
203 bt_audio_msg_header_t h
;
204 uint8_t data
[0]; /* First codec_capabilities_t */
205 } __attribute__ ((packed
));
207 struct bt_set_configuration_req
{
208 bt_audio_msg_header_t h
;
209 char device
[18]; /* Address of the remote Device */
210 uint8_t access_mode
; /* Requested access mode */
211 codec_capabilities_t codec
; /* Requested codec */
212 } __attribute__ ((packed
));
214 struct bt_set_configuration_rsp
{
215 bt_audio_msg_header_t h
;
216 uint8_t transport
; /* Granted transport */
217 uint8_t access_mode
; /* Granted access mode */
218 uint16_t link_mtu
; /* Max length that transport supports */
219 } __attribute__ ((packed
));
221 #define BT_STREAM_ACCESS_READ 0
222 #define BT_STREAM_ACCESS_WRITE 1
223 #define BT_STREAM_ACCESS_READWRITE 2
224 struct bt_start_stream_req
{
225 bt_audio_msg_header_t h
;
226 } __attribute__ ((packed
));
228 struct bt_start_stream_rsp
{
229 bt_audio_msg_header_t h
;
230 } __attribute__ ((packed
));
232 /* This message is followed by one byte of data containing the stream data fd
233 as ancilliary data */
234 struct bt_new_stream_ind
{
235 bt_audio_msg_header_t h
;
236 } __attribute__ ((packed
));
238 struct bt_stop_stream_req
{
239 bt_audio_msg_header_t h
;
240 } __attribute__ ((packed
));
242 struct bt_stop_stream_rsp
{
243 bt_audio_msg_header_t h
;
244 } __attribute__ ((packed
));
246 struct bt_suspend_stream_ind
{
247 bt_audio_msg_header_t h
;
248 } __attribute__ ((packed
));
250 struct bt_resume_stream_ind
{
251 bt_audio_msg_header_t h
;
252 } __attribute__ ((packed
));
254 #define BT_CONTROL_KEY_POWER 0x40
255 #define BT_CONTROL_KEY_VOL_UP 0x41
256 #define BT_CONTROL_KEY_VOL_DOWN 0x42
257 #define BT_CONTROL_KEY_MUTE 0x43
258 #define BT_CONTROL_KEY_PLAY 0x44
259 #define BT_CONTROL_KEY_STOP 0x45
260 #define BT_CONTROL_KEY_PAUSE 0x46
261 #define BT_CONTROL_KEY_RECORD 0x47
262 #define BT_CONTROL_KEY_REWIND 0x48
263 #define BT_CONTROL_KEY_FAST_FORWARD 0x49
264 #define BT_CONTROL_KEY_EJECT 0x4A
265 #define BT_CONTROL_KEY_FORWARD 0x4B
266 #define BT_CONTROL_KEY_BACKWARD 0x4C
268 struct bt_control_req
{
269 bt_audio_msg_header_t h
;
270 uint8_t mode
; /* Control Mode */
271 uint8_t key
; /* Control Key */
272 } __attribute__ ((packed
));
274 struct bt_control_rsp
{
275 bt_audio_msg_header_t h
;
276 uint8_t mode
; /* Control Mode */
277 uint8_t key
; /* Control Key */
278 } __attribute__ ((packed
));
280 struct bt_control_ind
{
281 bt_audio_msg_header_t h
;
282 uint8_t mode
; /* Control Mode */
283 uint8_t key
; /* Control Key */
284 } __attribute__ ((packed
));
286 /* Function declaration */
288 /* Opens a connection to the audio service: return a socket descriptor */
289 int bt_audio_service_open(void);
291 /* Closes a connection to the audio service */
292 int bt_audio_service_close(int sk
);
294 /* Receives stream data file descriptor : must be called after a
295 BT_STREAMFD_IND message is returned */
296 int bt_audio_service_get_data_fd(int sk
);
298 /* Human readable message type string */
299 const char *bt_audio_strtype(uint8_t type
);
301 /* Human readable message name string */
302 const char *bt_audio_strname(uint8_t name
);
308 #endif /* BT_AUDIOCLIENT_H */