ipc.h revision 9fa2613525721908ec43189794fe99828b8a4f51
1/*
2 *
3 *  BlueZ - Bluetooth protocol stack for Linux
4 *
5 *  Copyright (C) 2004-2007  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_GETCAPABILITIES_REQ
29
30  BT_GETCAPABILITIES_RSP-->
31
32                        on snd_pcm_hw_params
33                <--BT_SETCONFIGURATION_REQ
34
35  BT_SETCONFIGURATION_RSP-->
36
37			on snd_pcm_prepare
38                <--BT_STREAMSTART_REQ
39
40  <Moves to streaming state>
41  BT_STREAMSTART_RSP-->
42
43  BT_STREAMFD_IND -->
44
45                          <  streams data >
46                             ..........
47
48               on snd_pcm_drop/snd_pcm_drain
49
50                <--BT_STREAMSTOP_REQ
51
52  <Moves to open state>
53  BT_STREAMSTOP_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
64extern "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_AUDIO_IPC_PACKET_SIZE   128
75#define BT_IPC_SOCKET_NAME "\0/org/bluez/audio"
76
77/* Generic message header definition, except for RSP messages */
78typedef struct {
79	uint8_t msg_type;
80} __attribute__ ((packed)) bt_audio_msg_header_t;
81
82/* Generic message header definition, for all RSP messages */
83typedef struct {
84	bt_audio_msg_header_t	msg_h;
85	uint8_t			posix_errno;
86} __attribute__ ((packed)) bt_audio_rsp_msg_header_t;
87
88/* Messages list */
89#define BT_GETCAPABILITIES_REQ		0
90#define BT_GETCAPABILITIES_RSP		1
91
92#define BT_SETCONFIGURATION_REQ		2
93#define BT_SETCONFIGURATION_RSP		3
94
95#define BT_STREAMSTART_REQ		4
96#define BT_STREAMSTART_RSP		5
97
98#define BT_STREAMSTOP_REQ		6
99#define BT_STREAMSTOP_RSP		7
100
101#define BT_STREAMSUSPEND_IND		8
102#define BT_STREAMRESUME_IND		9
103
104#define BT_CONTROL_REQ		       10
105#define BT_CONTROL_RSP		       11
106#define BT_CONTROL_IND		       12
107
108#define BT_STREAMFD_IND		       13
109
110/* BT_GETCAPABILITIES_REQ */
111
112#define BT_CAPABILITIES_TRANSPORT_A2DP	0
113#define BT_CAPABILITIES_TRANSPORT_SCO	1
114#define BT_CAPABILITIES_TRANSPORT_ANY	2
115
116#define BT_CAPABILITIES_ACCESS_MODE_READ	1
117#define BT_CAPABILITIES_ACCESS_MODE_WRITE	2
118#define BT_CAPABILITIES_ACCESS_MODE_READWRITE	3
119
120#define BT_FLAG_AUTOCONNECT	1
121
122struct 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));
128
129/* BT_GETCAPABILITIES_RSP */
130
131/**
132 * SBC Codec parameters as per A2DP profile 1.0 § 4.3
133 */
134
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
139
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
144#define BT_A2DP_CHANNEL_MODE_AUTO		0
145
146#define BT_A2DP_BLOCK_LENGTH_4			(1 << 3)
147#define BT_A2DP_BLOCK_LENGTH_8			(1 << 2)
148#define BT_A2DP_BLOCK_LENGTH_12			(1 << 1)
149#define BT_A2DP_BLOCK_LENGTH_16			1
150
151#define BT_A2DP_SUBBANDS_4			(1 << 1)
152#define BT_A2DP_SUBBANDS_8			1
153
154#define BT_A2DP_ALLOCATION_SNR			(1 << 1)
155#define BT_A2DP_ALLOCATION_LOUDNESS		1
156#define BT_A2DP_ALLOCATION_AUTO			0
157
158#define BT_MPEG_SAMPLING_FREQ_16000		(1 << 5)
159#define BT_MPEG_SAMPLING_FREQ_22050		(1 << 4)
160#define BT_MPEG_SAMPLING_FREQ_24000		(1 << 3)
161#define BT_MPEG_SAMPLING_FREQ_32000		(1 << 2)
162#define BT_MPEG_SAMPLING_FREQ_44100		(1 << 1)
163#define BT_MPEG_SAMPLING_FREQ_48000		1
164
165#define BT_MPEG_LAYER_1				(1 << 2)
166#define BT_MPEG_LAYER_2				(1 << 1)
167#define BT_MPEG_LAYER_3				1
168
169typedef struct {
170	uint8_t channel_mode;
171	uint8_t frequency;
172	uint8_t allocation_method;
173	uint8_t subbands;
174	uint8_t block_length;
175	uint8_t min_bitpool;
176	uint8_t max_bitpool;
177} __attribute__ ((packed)) sbc_capabilities_t;
178
179typedef struct {
180	uint8_t channel_mode;
181	uint8_t crc;
182	uint8_t layer;
183	uint8_t frequency;
184	uint8_t mpf;
185	uint16_t bitrate;
186} __attribute__ ((packed)) mpeg_capabilities_t;
187
188struct bt_getcapabilities_rsp {
189	bt_audio_rsp_msg_header_t	rsp_h;
190	uint8_t				transport;	   /* Granted transport */
191	sbc_capabilities_t		sbc_capabilities;  /* A2DP only */
192	mpeg_capabilities_t		mpeg_capabilities; /* A2DP only */
193	uint16_t			sampling_rate;	   /* SCO only */
194} __attribute__ ((packed));
195
196/* BT_SETCONFIGURATION_REQ */
197struct bt_setconfiguration_req {
198	bt_audio_msg_header_t	h;
199	char			device[18];		/* Address of the remote Device */
200	uint8_t			transport;		/* Requested transport */
201	uint8_t			access_mode;		/* Requested access mode */
202	sbc_capabilities_t	sbc_capabilities;	/* A2DP only - only one of this field
203							and next one must be filled */
204	mpeg_capabilities_t	mpeg_capabilities;	/* A2DP only */
205} __attribute__ ((packed));
206
207/* BT_SETCONFIGURATION_RSP */
208struct bt_setconfiguration_rsp {
209	bt_audio_rsp_msg_header_t	rsp_h;
210	uint8_t				transport;	/* Granted transport */
211	uint8_t				access_mode;	/* Granted access mode */
212	uint16_t			link_mtu;	/* Max length that transport supports */
213} __attribute__ ((packed));
214
215/* BT_STREAMSTART_REQ */
216#define BT_STREAM_ACCESS_READ		0
217#define BT_STREAM_ACCESS_WRITE		1
218#define BT_STREAM_ACCESS_READWRITE	2
219struct bt_streamstart_req {
220	bt_audio_msg_header_t	h;
221} __attribute__ ((packed));
222
223/* BT_STREAMSTART_RSP */
224struct bt_streamstart_rsp {
225	bt_audio_rsp_msg_header_t	rsp_h;
226} __attribute__ ((packed));
227
228/* BT_STREAMFD_IND */
229/* This message is followed by one byte of data containing the stream data fd
230   as ancilliary data */
231struct bt_streamfd_ind {
232	bt_audio_msg_header_t	h;
233} __attribute__ ((packed));
234
235/* BT_STREAMSTOP_REQ */
236struct bt_streamstop_req {
237	bt_audio_msg_header_t	h;
238} __attribute__ ((packed));
239
240/* BT_STREAMSTOP_RSP */
241struct bt_streamstop_rsp {
242	bt_audio_rsp_msg_header_t	rsp_h;
243} __attribute__ ((packed));
244
245/* BT_STREAMSUSPEND_IND */
246struct bt_streamsuspend_ind {
247	bt_audio_msg_header_t	h;
248} __attribute__ ((packed));
249
250/* BT_STREAMRESUME_IND */
251struct bt_streamresume_ind {
252	bt_audio_msg_header_t	h;
253} __attribute__ ((packed));
254
255/* BT_CONTROL_REQ */
256
257#define BT_CONTROL_KEY_POWER			0x40
258#define BT_CONTROL_KEY_VOL_UP			0x41
259#define BT_CONTROL_KEY_VOL_DOWN			0x42
260#define BT_CONTROL_KEY_MUTE			0x43
261#define BT_CONTROL_KEY_PLAY			0x44
262#define BT_CONTROL_KEY_STOP			0x45
263#define BT_CONTROL_KEY_PAUSE			0x46
264#define BT_CONTROL_KEY_RECORD			0x47
265#define BT_CONTROL_KEY_REWIND			0x48
266#define BT_CONTROL_KEY_FAST_FORWARD		0x49
267#define BT_CONTROL_KEY_EJECT			0x4A
268#define BT_CONTROL_KEY_FORWARD			0x4B
269#define BT_CONTROL_KEY_BACKWARD			0x4C
270
271struct bt_control_req {
272	bt_audio_msg_header_t	h;
273	uint8_t			mode;		/* Control Mode */
274	uint8_t			key;		/* Control Key */
275} __attribute__ ((packed));
276
277/* BT_CONTROL_RSP */
278struct bt_control_rsp {
279	bt_audio_rsp_msg_header_t	rsp_h;
280	uint8_t				mode;	/* Control Mode */
281	uint8_t				key;	/* Control Key */
282} __attribute__ ((packed));
283
284/* BT_CONTROL_IND */
285struct bt_control_ind {
286	bt_audio_msg_header_t	h;
287	uint8_t			mode;		/* Control Mode */
288	uint8_t			key;		/* Control Key */
289} __attribute__ ((packed));
290
291/* Function declaration */
292
293/* Opens a connection to the audio service: return a socket descriptor */
294int bt_audio_service_open();
295
296/* Closes a connection to the audio service */
297int bt_audio_service_close(int sk);
298
299/* Receives stream data file descriptor : must be called after a
300BT_STREAMFD_IND message is returned */
301int bt_audio_service_get_data_fd(int sk);
302
303/* Human readable message type string */
304const char *bt_audio_strmsg(int type);
305
306#ifdef __cplusplus
307}
308#endif
309
310#endif /* BT_AUDIOCLIENT_H */
311