1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2006-2010  Nokia Corporation
6  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
7  *
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public
11  *  License as published by the Free Software Foundation; either
12  *  version 2.1 of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24 
25 #define A2DP_CODEC_SBC			0x00
26 #define A2DP_CODEC_MPEG12		0x01
27 #define A2DP_CODEC_MPEG24		0x02
28 #define A2DP_CODEC_ATRAC		0x03
29 #define A2DP_CODEC_VENDOR		0xFF
30 
31 #define SBC_SAMPLING_FREQ_16000		(1 << 3)
32 #define SBC_SAMPLING_FREQ_32000		(1 << 2)
33 #define SBC_SAMPLING_FREQ_44100		(1 << 1)
34 #define SBC_SAMPLING_FREQ_48000		1
35 
36 #define SBC_CHANNEL_MODE_MONO		(1 << 3)
37 #define SBC_CHANNEL_MODE_DUAL_CHANNEL	(1 << 2)
38 #define SBC_CHANNEL_MODE_STEREO		(1 << 1)
39 #define SBC_CHANNEL_MODE_JOINT_STEREO	1
40 
41 #define SBC_BLOCK_LENGTH_4		(1 << 3)
42 #define SBC_BLOCK_LENGTH_8		(1 << 2)
43 #define SBC_BLOCK_LENGTH_12		(1 << 1)
44 #define SBC_BLOCK_LENGTH_16		1
45 
46 #define SBC_SUBBANDS_4			(1 << 1)
47 #define SBC_SUBBANDS_8			1
48 
49 #define SBC_ALLOCATION_SNR		(1 << 1)
50 #define SBC_ALLOCATION_LOUDNESS		1
51 
52 #define MAX_BITPOOL 64
53 #define MIN_BITPOOL 2
54 
55 #define MPEG_CHANNEL_MODE_MONO		(1 << 3)
56 #define MPEG_CHANNEL_MODE_DUAL_CHANNEL	(1 << 2)
57 #define MPEG_CHANNEL_MODE_STEREO	(1 << 1)
58 #define MPEG_CHANNEL_MODE_JOINT_STEREO	1
59 
60 #define MPEG_LAYER_MP1			(1 << 2)
61 #define MPEG_LAYER_MP2			(1 << 1)
62 #define MPEG_LAYER_MP3			1
63 
64 #define MPEG_SAMPLING_FREQ_16000	(1 << 5)
65 #define MPEG_SAMPLING_FREQ_22050	(1 << 4)
66 #define MPEG_SAMPLING_FREQ_24000	(1 << 3)
67 #define MPEG_SAMPLING_FREQ_32000	(1 << 2)
68 #define MPEG_SAMPLING_FREQ_44100	(1 << 1)
69 #define MPEG_SAMPLING_FREQ_48000	1
70 
71 #define MPEG_BIT_RATE_VBR		0x8000
72 #define MPEG_BIT_RATE_320000		0x4000
73 #define MPEG_BIT_RATE_256000		0x2000
74 #define MPEG_BIT_RATE_224000		0x1000
75 #define MPEG_BIT_RATE_192000		0x0800
76 #define MPEG_BIT_RATE_160000		0x0400
77 #define MPEG_BIT_RATE_128000		0x0200
78 #define MPEG_BIT_RATE_112000		0x0100
79 #define MPEG_BIT_RATE_96000		0x0080
80 #define MPEG_BIT_RATE_80000		0x0040
81 #define MPEG_BIT_RATE_64000		0x0020
82 #define MPEG_BIT_RATE_56000		0x0010
83 #define MPEG_BIT_RATE_48000		0x0008
84 #define MPEG_BIT_RATE_40000		0x0004
85 #define MPEG_BIT_RATE_32000		0x0002
86 #define MPEG_BIT_RATE_FREE		0x0001
87 
88 #if __BYTE_ORDER == __LITTLE_ENDIAN
89 
90 typedef struct {
91 	uint8_t channel_mode:4;
92 	uint8_t frequency:4;
93 	uint8_t allocation_method:2;
94 	uint8_t subbands:2;
95 	uint8_t block_length:4;
96 	uint8_t min_bitpool;
97 	uint8_t max_bitpool;
98 } __attribute__ ((packed)) a2dp_sbc_t;
99 
100 typedef struct {
101 	uint8_t channel_mode:4;
102 	uint8_t crc:1;
103 	uint8_t layer:3;
104 	uint8_t frequency:6;
105 	uint8_t mpf:1;
106 	uint8_t rfa:1;
107 	uint16_t bitrate;
108 } __attribute__ ((packed)) a2dp_mpeg_t;
109 
110 #elif __BYTE_ORDER == __BIG_ENDIAN
111 
112 typedef struct {
113 	uint8_t frequency:4;
114 	uint8_t channel_mode:4;
115 	uint8_t block_length:4;
116 	uint8_t subbands:2;
117 	uint8_t allocation_method:2;
118 	uint8_t min_bitpool;
119 	uint8_t max_bitpool;
120 } __attribute__ ((packed)) a2dp_sbc_t;
121 
122 typedef struct {
123 	uint8_t layer:3;
124 	uint8_t crc:1;
125 	uint8_t channel_mode:4;
126 	uint8_t rfa:1;
127 	uint8_t mpf:1;
128 	uint8_t frequency:6;
129 	uint16_t bitrate;
130 } __attribute__ ((packed)) a2dp_mpeg_t;
131 
132 #else
133 #error "Unknown byte order"
134 #endif
135 
136 typedef struct {
137 	uint8_t vendor_id[4];
138 	uint8_t codec_id[2];
139 } __attribute__ ((packed)) a2dp_vendor_codec_t;
140