Home | History | Annotate | Download | only in audio
      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 (at) holtmann.org>
      7  *
      8  *
      9  *  This program is free software; you can redistribute it and/or modify
     10  *  it under the terms of the GNU General Public License as published by
     11  *  the Free Software Foundation; either version 2 of the License, or
     12  *  (at your option) any later version.
     13  *
     14  *  This program 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
     17  *  GNU General Public License for more details.
     18  *
     19  *  You should have received a copy of the GNU General Public License
     20  *  along with this program; if not, write to the Free Software
     21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     22  *
     23  */
     24 
     25 typedef enum {
     26 	AVDTP_ERROR_ERRNO,
     27 	AVDTP_ERROR_ERROR_CODE
     28 } avdtp_error_type_t;
     29 
     30 typedef enum {
     31 	AVDTP_SESSION_STATE_DISCONNECTED,
     32 	AVDTP_SESSION_STATE_CONNECTING,
     33 	AVDTP_SESSION_STATE_CONNECTED
     34 } avdtp_session_state_t;
     35 
     36 struct avdtp;
     37 struct avdtp_stream;
     38 struct avdtp_local_sep;
     39 struct avdtp_remote_sep;
     40 struct avdtp_error {
     41 	avdtp_error_type_t type;
     42 	union {
     43 		uint8_t error_code;
     44 		int posix_errno;
     45 	} err;
     46 };
     47 
     48 /* SEP capability categories */
     49 #define AVDTP_MEDIA_TRANSPORT			0x01
     50 #define AVDTP_REPORTING				0x02
     51 #define AVDTP_RECOVERY				0x03
     52 #define AVDTP_CONTENT_PROTECTION		0x04
     53 #define AVDTP_HEADER_COMPRESSION		0x05
     54 #define AVDTP_MULTIPLEXING			0x06
     55 #define AVDTP_MEDIA_CODEC			0x07
     56 #define AVDTP_DELAY_REPORTING			0x08
     57 
     58 /* AVDTP error definitions */
     59 #define AVDTP_BAD_HEADER_FORMAT			0x01
     60 #define AVDTP_BAD_LENGTH			0x11
     61 #define AVDTP_BAD_ACP_SEID			0x12
     62 #define AVDTP_SEP_IN_USE			0x13
     63 #define AVDTP_SEP_NOT_IN_USE			0x14
     64 #define AVDTP_BAD_SERV_CATEGORY			0x17
     65 #define AVDTP_BAD_PAYLOAD_FORMAT		0x18
     66 #define AVDTP_NOT_SUPPORTED_COMMAND		0x19
     67 #define AVDTP_INVALID_CAPABILITIES		0x1A
     68 #define AVDTP_BAD_RECOVERY_TYPE			0x22
     69 #define AVDTP_BAD_MEDIA_TRANSPORT_FORMAT	0x23
     70 #define AVDTP_BAD_RECOVERY_FORMAT		0x25
     71 #define AVDTP_BAD_ROHC_FORMAT			0x26
     72 #define AVDTP_BAD_CP_FORMAT			0x27
     73 #define AVDTP_BAD_MULTIPLEXING_FORMAT		0x28
     74 #define AVDTP_UNSUPPORTED_CONFIGURATION		0x29
     75 #define AVDTP_BAD_STATE				0x31
     76 
     77 /* SEP types definitions */
     78 #define AVDTP_SEP_TYPE_SOURCE			0x00
     79 #define AVDTP_SEP_TYPE_SINK			0x01
     80 
     81 /* Media types definitions */
     82 #define AVDTP_MEDIA_TYPE_AUDIO			0x00
     83 #define AVDTP_MEDIA_TYPE_VIDEO			0x01
     84 #define AVDTP_MEDIA_TYPE_MULTIMEDIA		0x02
     85 
     86 typedef enum {
     87 	AVDTP_STATE_IDLE,
     88 	AVDTP_STATE_CONFIGURED,
     89 	AVDTP_STATE_OPEN,
     90 	AVDTP_STATE_STREAMING,
     91 	AVDTP_STATE_CLOSING,
     92 	AVDTP_STATE_ABORTING,
     93 } avdtp_state_t;
     94 
     95 struct avdtp_service_capability {
     96 	uint8_t category;
     97 	uint8_t length;
     98 	uint8_t data[0];
     99 } __attribute__ ((packed));
    100 
    101 #if __BYTE_ORDER == __LITTLE_ENDIAN
    102 
    103 struct avdtp_media_codec_capability {
    104 	uint8_t rfa0:4;
    105 	uint8_t media_type:4;
    106 	uint8_t media_codec_type;
    107 	uint8_t data[0];
    108 } __attribute__ ((packed));
    109 
    110 #elif __BYTE_ORDER == __BIG_ENDIAN
    111 
    112 struct avdtp_media_codec_capability {
    113 	uint8_t media_type:4;
    114 	uint8_t rfa0:4;
    115 	uint8_t media_codec_type;
    116 	uint8_t data[0];
    117 } __attribute__ ((packed));
    118 
    119 #else
    120 #error "Unknown byte order"
    121 #endif
    122 
    123 typedef void (*avdtp_session_state_cb) (struct audio_device *dev,
    124 					struct avdtp *session,
    125 					avdtp_session_state_t old_state,
    126 					avdtp_session_state_t new_state,
    127 					void *user_data);
    128 
    129 typedef void (*avdtp_stream_state_cb) (struct avdtp_stream *stream,
    130 					avdtp_state_t old_state,
    131 					avdtp_state_t new_state,
    132 					struct avdtp_error *err,
    133 					void *user_data);
    134 
    135 /* Callbacks for when a reply is received to a command that we sent */
    136 struct avdtp_sep_cfm {
    137 	void (*set_configuration) (struct avdtp *session,
    138 					struct avdtp_local_sep *lsep,
    139 					struct avdtp_stream *stream,
    140 					struct avdtp_error *err,
    141 					void *user_data);
    142 	void (*get_configuration) (struct avdtp *session,
    143 					struct avdtp_local_sep *lsep,
    144 					struct avdtp_stream *stream,
    145 					struct avdtp_error *err,
    146 					void *user_data);
    147 	void (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
    148 			struct avdtp_stream *stream, struct avdtp_error *err,
    149 			void *user_data);
    150 	void (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
    151 			struct avdtp_stream *stream, struct avdtp_error *err,
    152 			void *user_data);
    153 	void (*suspend) (struct avdtp *session, struct avdtp_local_sep *lsep,
    154 				struct avdtp_stream *stream,
    155 				struct avdtp_error *err, void *user_data);
    156 	void (*close) (struct avdtp *session, struct avdtp_local_sep *lsep,
    157 				struct avdtp_stream *stream,
    158 				struct avdtp_error *err, void *user_data);
    159 	void (*abort) (struct avdtp *session, struct avdtp_local_sep *lsep,
    160 				struct avdtp_stream *stream,
    161 				struct avdtp_error *err, void *user_data);
    162 	void (*reconfigure) (struct avdtp *session,
    163 				struct avdtp_local_sep *lsep,
    164 				struct avdtp_stream *stream,
    165 				struct avdtp_error *err, void *user_data);
    166 	void (*delay_report) (struct avdtp *session, struct avdtp_local_sep *lsep,
    167 				struct avdtp_stream *stream,
    168 				struct avdtp_error *err, void *user_data);
    169 };
    170 
    171 /* Callbacks for indicating when we received a new command. The return value
    172  * indicates whether the command should be rejected or accepted */
    173 struct avdtp_sep_ind {
    174 	gboolean (*get_capability) (struct avdtp *session,
    175 					struct avdtp_local_sep *sep,
    176 					gboolean get_all,
    177 					GSList **caps, uint8_t *err,
    178 					void *user_data);
    179 	gboolean (*set_configuration) (struct avdtp *session,
    180 					struct avdtp_local_sep *lsep,
    181 					struct avdtp_stream *stream,
    182 					GSList *caps, uint8_t *err,
    183 					uint8_t *category, void *user_data);
    184 	gboolean (*get_configuration) (struct avdtp *session,
    185 					struct avdtp_local_sep *lsep,
    186 					uint8_t *err, void *user_data);
    187 	gboolean (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
    188 				struct avdtp_stream *stream, uint8_t *err,
    189 				void *user_data);
    190 	gboolean (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
    191 				struct avdtp_stream *stream, uint8_t *err,
    192 				void *user_data);
    193 	gboolean (*suspend) (struct avdtp *session,
    194 				struct avdtp_local_sep *sep,
    195 				struct avdtp_stream *stream, uint8_t *err,
    196 				void *user_data);
    197 	gboolean (*close) (struct avdtp *session, struct avdtp_local_sep *sep,
    198 				struct avdtp_stream *stream, uint8_t *err,
    199 				void *user_data);
    200 	gboolean (*abort) (struct avdtp *session, struct avdtp_local_sep *sep,
    201 				struct avdtp_stream *stream, uint8_t *err,
    202 				void *user_data);
    203 	gboolean (*reconfigure) (struct avdtp *session,
    204 					struct avdtp_local_sep *lsep,
    205 					uint8_t *err, void *user_data);
    206 	gboolean (*delayreport) (struct avdtp *session,
    207 					struct avdtp_local_sep *lsep,
    208 					uint8_t rseid, uint16_t delay,
    209 					uint8_t *err, void *user_data);
    210 };
    211 
    212 typedef void (*avdtp_discover_cb_t) (struct avdtp *session, GSList *seps,
    213 					struct avdtp_error *err, void *user_data);
    214 
    215 struct avdtp *avdtp_get(bdaddr_t *src, bdaddr_t *dst);
    216 
    217 void avdtp_unref(struct avdtp *session);
    218 struct avdtp *avdtp_ref(struct avdtp *session);
    219 
    220 gboolean avdtp_is_connected(const bdaddr_t *src, const bdaddr_t *dst);
    221 
    222 struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
    223 							void *data, int size);
    224 
    225 struct avdtp_remote_sep *avdtp_get_remote_sep(struct avdtp *session,
    226 						uint8_t seid);
    227 
    228 uint8_t avdtp_get_seid(struct avdtp_remote_sep *sep);
    229 
    230 uint8_t avdtp_get_type(struct avdtp_remote_sep *sep);
    231 
    232 struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep);
    233 
    234 gboolean avdtp_get_delay_reporting(struct avdtp_remote_sep *sep);
    235 
    236 struct avdtp_stream *avdtp_get_stream(struct avdtp_remote_sep *sep);
    237 
    238 int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
    239 			void *user_data);
    240 
    241 gboolean avdtp_has_stream(struct avdtp *session, struct avdtp_stream *stream);
    242 
    243 unsigned int avdtp_stream_add_cb(struct avdtp *session,
    244 					struct avdtp_stream *stream,
    245 					avdtp_stream_state_cb cb, void *data);
    246 gboolean avdtp_stream_remove_cb(struct avdtp *session,
    247 				struct avdtp_stream *stream,
    248 				unsigned int id);
    249 
    250 gboolean avdtp_stream_get_transport(struct avdtp_stream *stream, int *sock,
    251 					uint16_t *imtu, uint16_t *omtu,
    252 					GSList **caps);
    253 struct avdtp_service_capability *avdtp_stream_get_codec(
    254 						struct avdtp_stream *stream);
    255 gboolean avdtp_stream_has_capability(struct avdtp_stream *stream,
    256 				struct avdtp_service_capability *cap);
    257 gboolean avdtp_stream_has_capabilities(struct avdtp_stream *stream,
    258 					GSList *caps);
    259 
    260 unsigned int avdtp_add_state_cb(avdtp_session_state_cb cb, void *user_data);
    261 
    262 gboolean avdtp_remove_state_cb(unsigned int id);
    263 
    264 int avdtp_set_configuration(struct avdtp *session,
    265 				struct avdtp_remote_sep *rsep,
    266 				struct avdtp_local_sep *lsep,
    267 				GSList *caps,
    268 				struct avdtp_stream **stream);
    269 
    270 int avdtp_get_configuration(struct avdtp *session,
    271 				struct avdtp_stream *stream);
    272 
    273 int avdtp_open(struct avdtp *session, struct avdtp_stream *stream);
    274 int avdtp_reconfigure(struct avdtp *session, GSList *caps,
    275 			struct avdtp_stream *stream);
    276 int avdtp_start(struct avdtp *session, struct avdtp_stream *stream);
    277 int avdtp_suspend(struct avdtp *session, struct avdtp_stream *stream);
    278 int avdtp_close(struct avdtp *session, struct avdtp_stream *stream,
    279 		gboolean immediate);
    280 int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
    281 int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
    282 							uint16_t delay);
    283 
    284 struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
    285 						uint8_t media_type,
    286 						uint8_t codec_type,
    287 						gboolean delay_reporting,
    288 						struct avdtp_sep_ind *ind,
    289 						struct avdtp_sep_cfm *cfm,
    290 						void *user_data);
    291 
    292 /* Find a matching pair of local and remote SEP ID's */
    293 int avdtp_get_seps(struct avdtp *session, uint8_t type, uint8_t media,
    294 			uint8_t codec, struct avdtp_local_sep **lsep,
    295 			struct avdtp_remote_sep **rsep);
    296 
    297 int avdtp_unregister_sep(struct avdtp_local_sep *sep);
    298 
    299 avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep);
    300 
    301 void avdtp_error_init(struct avdtp_error *err, uint8_t type, int id);
    302 const char *avdtp_strerror(struct avdtp_error *err);
    303 avdtp_error_type_t avdtp_error_type(struct avdtp_error *err);
    304 int avdtp_error_error_code(struct avdtp_error *err);
    305 int avdtp_error_posix_errno(struct avdtp_error *err);
    306 
    307 void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst);
    308 
    309 void avdtp_set_auto_disconnect(struct avdtp *session, gboolean auto_dc);
    310 gboolean avdtp_stream_setup_active(struct avdtp *session);
    311 
    312 int avdtp_init(const bdaddr_t *src, GKeyFile *config, uint16_t *version);
    313 void avdtp_exit(const bdaddr_t *src);
    314