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_GETCAPABILITIES_REQ
30
BT_GETCAPABILITIES_RSP-->
33
<--BT_SETCONFIGURATION_REQ
35
BT_SETCONFIGURATION_RSP-->
40
<Moves to streaming state>
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_AUDIO_IPC_PACKET_SIZE 128
75
#define BT_IPC_SOCKET_NAME "\0/org/bluez/audio"
77
/* Generic message header definition, except for RSP messages */
80
} __attribute__ ((packed)) bt_audio_msg_header_t;
82
/* Generic message header definition, for all RSP messages */
84
bt_audio_msg_header_t msg_h;
86
} __attribute__ ((packed)) bt_audio_rsp_msg_header_t;
89
#define BT_GETCAPABILITIES_REQ 0
90
#define BT_GETCAPABILITIES_RSP 1
92
#define BT_SETCONFIGURATION_REQ 2
93
#define BT_SETCONFIGURATION_RSP 3
95
#define BT_STREAMSTART_REQ 4
96
#define BT_STREAMSTART_RSP 5
98
#define BT_STREAMSTOP_REQ 6
99
#define BT_STREAMSTOP_RSP 7
101
#define BT_STREAMSUSPEND_IND 8
102
#define BT_STREAMRESUME_IND 9
104
#define BT_CONTROL_REQ 10
105
#define BT_CONTROL_RSP 11
106
#define BT_CONTROL_IND 12
108
#define BT_STREAMFD_IND 13
110
/* BT_GETCAPABILITIES_REQ */
112
#define BT_CAPABILITIES_TRANSPORT_A2DP 0
113
#define BT_CAPABILITIES_TRANSPORT_SCO 1
114
#define BT_CAPABILITIES_TRANSPORT_ANY 2
116
#define BT_CAPABILITIES_ACCESS_MODE_READ 1
117
#define BT_CAPABILITIES_ACCESS_MODE_WRITE 2
118
#define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3
120
#define BT_FLAG_AUTOCONNECT 1
122
struct bt_getcapabilities_req {
123
bt_audio_msg_header_t h;
124
char device[18]; /* Address of the remote Device */
125
uint8_t transport; /* Requested transport */
126
uint8_t flags; /* Requested flags */
127
} __attribute__ ((packed));
129
/* BT_GETCAPABILITIES_RSP */
132
* SBC Codec parameters as per A2DP profile 1.0 § 4.3
135
#define BT_SBC_SAMPLING_FREQ_16000 (1 << 3)
136
#define BT_SBC_SAMPLING_FREQ_32000 (1 << 2)
137
#define BT_SBC_SAMPLING_FREQ_44100 (1 << 1)
138
#define BT_SBC_SAMPLING_FREQ_48000 1
140
#define BT_A2DP_CHANNEL_MODE_MONO (1 << 3)
141
#define BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
142
#define BT_A2DP_CHANNEL_MODE_STEREO (1 << 1)
143
#define BT_A2DP_CHANNEL_MODE_JOINT_STEREO 1
145
#define BT_A2DP_BLOCK_LENGTH_4 (1 << 3)
146
#define BT_A2DP_BLOCK_LENGTH_8 (1 << 2)
147
#define BT_A2DP_BLOCK_LENGTH_12 (1 << 1)
148
#define BT_A2DP_BLOCK_LENGTH_16 1
150
#define BT_A2DP_SUBBANDS_4 (1 << 1)
151
#define BT_A2DP_SUBBANDS_8 1
153
#define BT_A2DP_ALLOCATION_SNR (1 << 1)
154
#define BT_A2DP_ALLOCATION_LOUDNESS 1
156
#define BT_MPEG_SAMPLING_FREQ_16000 (1 << 5)
157
#define BT_MPEG_SAMPLING_FREQ_22050 (1 << 4)
158
#define BT_MPEG_SAMPLING_FREQ_24000 (1 << 3)
159
#define BT_MPEG_SAMPLING_FREQ_32000 (1 << 2)
160
#define BT_MPEG_SAMPLING_FREQ_44100 (1 << 1)
161
#define BT_MPEG_SAMPLING_FREQ_48000 1
163
#define BT_MPEG_LAYER_1 (1 << 2)
164
#define BT_MPEG_LAYER_2 (1 << 1)
165
#define BT_MPEG_LAYER_3 1
168
uint8_t channel_mode;
170
uint8_t allocation_method;
172
uint8_t block_length;
175
} __attribute__ ((packed)) sbc_capabilities_t;
178
uint8_t channel_mode;
184
} __attribute__ ((packed)) mpeg_capabilities_t;
186
struct bt_getcapabilities_rsp {
187
bt_audio_rsp_msg_header_t rsp_h;
188
uint8_t transport; /* Granted transport */
189
sbc_capabilities_t sbc_capabilities; /* A2DP only */
190
mpeg_capabilities_t mpeg_capabilities; /* A2DP only */
191
uint16_t sampling_rate; /* SCO only */
192
} __attribute__ ((packed));
194
/* BT_SETCONFIGURATION_REQ */
195
struct bt_setconfiguration_req {
196
bt_audio_msg_header_t h;
197
char device[18]; /* Address of the remote Device */
198
uint8_t transport; /* Requested transport */
199
uint8_t access_mode; /* Requested access mode */
200
sbc_capabilities_t sbc_capabilities; /* A2DP only - only one of this field
201
and next one must be filled */
202
mpeg_capabilities_t mpeg_capabilities; /* A2DP only */
203
} __attribute__ ((packed));
205
/* BT_SETCONFIGURATION_RSP */
206
struct bt_setconfiguration_rsp {
207
bt_audio_rsp_msg_header_t rsp_h;
208
uint8_t transport; /* Granted transport */
209
uint8_t access_mode; /* Granted access mode */
210
uint16_t link_mtu; /* Max length that transport supports */
211
} __attribute__ ((packed));
213
/* BT_STREAMSTART_REQ */
214
#define BT_STREAM_ACCESS_READ 0
215
#define BT_STREAM_ACCESS_WRITE 1
216
#define BT_STREAM_ACCESS_READWRITE 2
217
struct bt_streamstart_req {
218
bt_audio_msg_header_t h;
219
} __attribute__ ((packed));
221
/* BT_STREAMSTART_RSP */
222
struct bt_streamstart_rsp {
223
bt_audio_rsp_msg_header_t rsp_h;
224
} __attribute__ ((packed));
226
/* BT_STREAMFD_IND */
227
/* This message is followed by one byte of data containing the stream data fd
228
as ancilliary data */
229
struct bt_streamfd_ind {
230
bt_audio_msg_header_t h;
231
} __attribute__ ((packed));
233
/* BT_STREAMSTOP_REQ */
234
struct bt_streamstop_req {
235
bt_audio_msg_header_t h;
236
} __attribute__ ((packed));
238
/* BT_STREAMSTOP_RSP */
239
struct bt_streamstop_rsp {
240
bt_audio_rsp_msg_header_t rsp_h;
241
} __attribute__ ((packed));
243
/* BT_STREAMSUSPEND_IND */
244
struct bt_streamsuspend_ind {
245
bt_audio_msg_header_t h;
246
} __attribute__ ((packed));
248
/* BT_STREAMRESUME_IND */
249
struct bt_streamresume_ind {
250
bt_audio_msg_header_t h;
251
} __attribute__ ((packed));
255
#define BT_CONTROL_KEY_POWER 0x40
256
#define BT_CONTROL_KEY_VOL_UP 0x41
257
#define BT_CONTROL_KEY_VOL_DOWN 0x42
258
#define BT_CONTROL_KEY_MUTE 0x43
259
#define BT_CONTROL_KEY_PLAY 0x44
260
#define BT_CONTROL_KEY_STOP 0x45
261
#define BT_CONTROL_KEY_PAUSE 0x46
262
#define BT_CONTROL_KEY_RECORD 0x47
263
#define BT_CONTROL_KEY_REWIND 0x48
264
#define BT_CONTROL_KEY_FAST_FORWARD 0x49
265
#define BT_CONTROL_KEY_EJECT 0x4A
266
#define BT_CONTROL_KEY_FORWARD 0x4B
267
#define BT_CONTROL_KEY_BACKWARD 0x4C
269
struct bt_control_req {
270
bt_audio_msg_header_t h;
271
uint8_t mode; /* Control Mode */
272
uint8_t key; /* Control Key */
273
} __attribute__ ((packed));
276
struct bt_control_rsp {
277
bt_audio_rsp_msg_header_t rsp_h;
278
uint8_t mode; /* Control Mode */
279
uint8_t key; /* Control Key */
280
} __attribute__ ((packed));
283
struct bt_control_ind {
284
bt_audio_msg_header_t h;
285
uint8_t mode; /* Control Mode */
286
uint8_t key; /* Control Key */
287
} __attribute__ ((packed));
289
/* Function declaration */
291
/* Opens a connection to the audio service: return a socket descriptor */
292
int bt_audio_service_open(void);
294
/* Closes a connection to the audio service */
295
int bt_audio_service_close(int sk);
297
/* Receives stream data file descriptor : must be called after a
298
BT_STREAMFD_IND message is returned */
299
int bt_audio_service_get_data_fd(int sk);
301
/* Human readable message type string */
302
const char *bt_audio_strmsg(int type);
308
#endif /* BT_AUDIOCLIENT_H */