]> code.delx.au - pulseaudio/blob - src/modules/bluetooth/ipc.h
Merge commit 'origin/master-tx'
[pulseaudio] / src / modules / bluetooth / ipc.h
1 /*
2 *
3 * BlueZ - Bluetooth protocol stack for Linux
4 *
5 * Copyright (C) 2004-2009 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 128
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_SET_CONFIGURATION 1
98 #define BT_NEW_STREAM 2
99 #define BT_START_STREAM 3
100 #define BT_STOP_STREAM 4
101 #define BT_CONTROL 7
102
103 #define BT_CAPABILITIES_TRANSPORT_A2DP 0
104 #define BT_CAPABILITIES_TRANSPORT_SCO 1
105 #define BT_CAPABILITIES_TRANSPORT_ANY 2
106
107 #define BT_CAPABILITIES_ACCESS_MODE_READ 1
108 #define BT_CAPABILITIES_ACCESS_MODE_WRITE 2
109 #define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3
110
111 #define BT_FLAG_AUTOCONNECT 1
112
113 struct bt_get_capabilities_req {
114 bt_audio_msg_header_t h;
115 char device[18]; /* Address of the remote Device */
116 uint8_t transport; /* Requested transport */
117 uint8_t flags; /* Requested flags */
118 } __attribute__ ((packed));
119
120 /**
121 * SBC Codec parameters as per A2DP profile 1.0 § 4.3
122 */
123
124 #define BT_A2DP_CODEC_SBC 0x00
125 #define BT_A2DP_CODEC_MPEG12 0x01
126 #define BT_A2DP_CODEC_MPEG24 0x02
127 #define BT_A2DP_CODEC_ATRAC 0x03
128
129 #define BT_SBC_SAMPLING_FREQ_16000 (1 << 3)
130 #define BT_SBC_SAMPLING_FREQ_32000 (1 << 2)
131 #define BT_SBC_SAMPLING_FREQ_44100 (1 << 1)
132 #define BT_SBC_SAMPLING_FREQ_48000 1
133
134 #define BT_A2DP_CHANNEL_MODE_MONO (1 << 3)
135 #define BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
136 #define BT_A2DP_CHANNEL_MODE_STEREO (1 << 1)
137 #define BT_A2DP_CHANNEL_MODE_JOINT_STEREO 1
138
139 #define BT_A2DP_BLOCK_LENGTH_4 (1 << 3)
140 #define BT_A2DP_BLOCK_LENGTH_8 (1 << 2)
141 #define BT_A2DP_BLOCK_LENGTH_12 (1 << 1)
142 #define BT_A2DP_BLOCK_LENGTH_16 1
143
144 #define BT_A2DP_SUBBANDS_4 (1 << 1)
145 #define BT_A2DP_SUBBANDS_8 1
146
147 #define BT_A2DP_ALLOCATION_SNR (1 << 1)
148 #define BT_A2DP_ALLOCATION_LOUDNESS 1
149
150 #define BT_MPEG_SAMPLING_FREQ_16000 (1 << 5)
151 #define BT_MPEG_SAMPLING_FREQ_22050 (1 << 4)
152 #define BT_MPEG_SAMPLING_FREQ_24000 (1 << 3)
153 #define BT_MPEG_SAMPLING_FREQ_32000 (1 << 2)
154 #define BT_MPEG_SAMPLING_FREQ_44100 (1 << 1)
155 #define BT_MPEG_SAMPLING_FREQ_48000 1
156
157 #define BT_MPEG_LAYER_1 (1 << 2)
158 #define BT_MPEG_LAYER_2 (1 << 1)
159 #define BT_MPEG_LAYER_3 1
160
161 #define BT_HFP_CODEC_PCM 0x00
162
163 #define BT_PCM_FLAG_NREC 0x01
164 #define BT_PCM_FLAG_PCM_ROUTING 0x02
165
166 typedef struct {
167 uint8_t transport;
168 uint8_t type;
169 uint8_t length;
170 uint8_t data[0];
171 } __attribute__ ((packed)) codec_capabilities_t;
172
173 typedef struct {
174 codec_capabilities_t capability;
175 uint8_t channel_mode;
176 uint8_t frequency;
177 uint8_t allocation_method;
178 uint8_t subbands;
179 uint8_t block_length;
180 uint8_t min_bitpool;
181 uint8_t max_bitpool;
182 } __attribute__ ((packed)) sbc_capabilities_t;
183
184 typedef struct {
185 codec_capabilities_t capability;
186 uint8_t channel_mode;
187 uint8_t crc;
188 uint8_t layer;
189 uint8_t frequency;
190 uint8_t mpf;
191 uint16_t bitrate;
192 } __attribute__ ((packed)) mpeg_capabilities_t;
193
194 typedef struct {
195 codec_capabilities_t capability;
196 uint8_t flags;
197 uint16_t sampling_rate;
198 } __attribute__ ((packed)) pcm_capabilities_t;
199
200 struct bt_get_capabilities_rsp {
201 bt_audio_msg_header_t h;
202 uint8_t data[0]; /* First codec_capabilities_t */
203 } __attribute__ ((packed));
204
205 struct bt_set_configuration_req {
206 bt_audio_msg_header_t h;
207 char device[18]; /* Address of the remote Device */
208 uint8_t access_mode; /* Requested access mode */
209 codec_capabilities_t codec; /* Requested codec */
210 } __attribute__ ((packed));
211
212 struct bt_set_configuration_rsp {
213 bt_audio_msg_header_t h;
214 uint8_t transport; /* Granted transport */
215 uint8_t access_mode; /* Granted access mode */
216 uint16_t link_mtu; /* Max length that transport supports */
217 } __attribute__ ((packed));
218
219 #define BT_STREAM_ACCESS_READ 0
220 #define BT_STREAM_ACCESS_WRITE 1
221 #define BT_STREAM_ACCESS_READWRITE 2
222 struct bt_start_stream_req {
223 bt_audio_msg_header_t h;
224 } __attribute__ ((packed));
225
226 struct bt_start_stream_rsp {
227 bt_audio_msg_header_t h;
228 } __attribute__ ((packed));
229
230 /* This message is followed by one byte of data containing the stream data fd
231 as ancilliary data */
232 struct bt_new_stream_ind {
233 bt_audio_msg_header_t h;
234 } __attribute__ ((packed));
235
236 struct bt_stop_stream_req {
237 bt_audio_msg_header_t h;
238 } __attribute__ ((packed));
239
240 struct bt_stop_stream_rsp {
241 bt_audio_msg_header_t h;
242 } __attribute__ ((packed));
243
244 struct bt_suspend_stream_ind {
245 bt_audio_msg_header_t h;
246 } __attribute__ ((packed));
247
248 struct bt_resume_stream_ind {
249 bt_audio_msg_header_t h;
250 } __attribute__ ((packed));
251
252 #define BT_CONTROL_KEY_POWER 0x40
253 #define BT_CONTROL_KEY_VOL_UP 0x41
254 #define BT_CONTROL_KEY_VOL_DOWN 0x42
255 #define BT_CONTROL_KEY_MUTE 0x43
256 #define BT_CONTROL_KEY_PLAY 0x44
257 #define BT_CONTROL_KEY_STOP 0x45
258 #define BT_CONTROL_KEY_PAUSE 0x46
259 #define BT_CONTROL_KEY_RECORD 0x47
260 #define BT_CONTROL_KEY_REWIND 0x48
261 #define BT_CONTROL_KEY_FAST_FORWARD 0x49
262 #define BT_CONTROL_KEY_EJECT 0x4A
263 #define BT_CONTROL_KEY_FORWARD 0x4B
264 #define BT_CONTROL_KEY_BACKWARD 0x4C
265
266 struct bt_control_req {
267 bt_audio_msg_header_t h;
268 uint8_t mode; /* Control Mode */
269 uint8_t key; /* Control Key */
270 } __attribute__ ((packed));
271
272 struct bt_control_rsp {
273 bt_audio_msg_header_t h;
274 uint8_t mode; /* Control Mode */
275 uint8_t key; /* Control Key */
276 } __attribute__ ((packed));
277
278 struct bt_control_ind {
279 bt_audio_msg_header_t h;
280 uint8_t mode; /* Control Mode */
281 uint8_t key; /* Control Key */
282 } __attribute__ ((packed));
283
284 /* Function declaration */
285
286 /* Opens a connection to the audio service: return a socket descriptor */
287 int bt_audio_service_open(void);
288
289 /* Closes a connection to the audio service */
290 int bt_audio_service_close(int sk);
291
292 /* Receives stream data file descriptor : must be called after a
293 BT_STREAMFD_IND message is returned */
294 int bt_audio_service_get_data_fd(int sk);
295
296 /* Human readable message type string */
297 const char *bt_audio_strtype(uint8_t type);
298
299 /* Human readable message name string */
300 const char *bt_audio_strname(uint8_t name);
301
302 #ifdef __cplusplus
303 }
304 #endif
305
306 #endif /* BT_AUDIOCLIENT_H */