Home | History | Annotate | Download | only in audio
      1 /*
      2  *
      3  *  BlueZ - Bluetooth protocol stack for Linux
      4  *
      5  *  Copyright (C) 2006-2007  Nokia Corporation
      6  *  Copyright (C) 2004-2009  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 
     57 /* AVDTP error definitions */
     58 #define AVDTP_BAD_HEADER_FORMAT			0x01
     59 #define AVDTP_BAD_LENGTH			0x11
     60 #define AVDTP_BAD_ACP_SEID			0x12
     61 #define AVDTP_SEP_IN_USE			0x13
     62 #define AVDTP_SEP_NOT_IN_USE			0x14
     63 #define AVDTP_BAD_SERV_CATEGORY			0x17
     64 #define AVDTP_BAD_PAYLOAD_FORMAT		0x18
     65 #define AVDTP_NOT_SUPPORTED_COMMAND		0x19
     66 #define AVDTP_INVALID_CAPABILITIES		0x1A
     67 #define AVDTP_BAD_RECOVERY_TYPE			0x22
     68 #define AVDTP_BAD_MEDIA_TRANSPORT_FORMAT	0x23
     69 #define AVDTP_BAD_RECOVERY_FORMAT		0x25
     70 #define AVDTP_BAD_ROHC_FORMAT			0x26
     71 #define AVDTP_BAD_CP_FORMAT			0x27
     72 #define AVDTP_BAD_MULTIPLEXING_FORMAT		0x28
     73 #define AVDTP_UNSUPPORTED_CONFIGURATION		0x29
     74 #define AVDTP_BAD_STATE				0x31
     75 
     76 /* SEP types definitions */
     77 #define AVDTP_SEP_TYPE_SOURCE			0x00
     78 #define AVDTP_SEP_TYPE_SINK			0x01
     79 
     80 /* Media types definitions */
     81 #define AVDTP_MEDIA_TYPE_AUDIO			0x00
     82 #define AVDTP_MEDIA_TYPE_VIDEO			0x01
     83 #define AVDTP_MEDIA_TYPE_MULTIMEDIA		0x02
     84 
     85 typedef enum {
     86 	AVDTP_STATE_IDLE,
     87 	AVDTP_STATE_CONFIGURED,
     88 	AVDTP_STATE_OPEN,
     89 	AVDTP_STATE_STREAMING,
     90 	AVDTP_STATE_CLOSING,
     91 	AVDTP_STATE_ABORTING,
     92 } avdtp_state_t;
     93 
     94 struct avdtp_service_capability {
     95 	uint8_t category;
     96 	uint8_t length;
     97 	uint8_t data[0];
     98 } __attribute__ ((packed));
     99 
    100 #if __BYTE_ORDER == __LITTLE_ENDIAN
    101 
    102 struct avdtp_media_codec_capability {
    103 	uint8_t rfa0:4;
    104 	uint8_t media_type:4;
    105 	uint8_t media_codec_type;
    106 	uint8_t data[0];
    107 } __attribute__ ((packed));
    108 
    109 #elif __BYTE_ORDER == __BIG_ENDIAN
    110 
    111 struct avdtp_media_codec_capability {
    112 	uint8_t media_type:4;
    113 	uint8_t rfa0:4;
    114 	uint8_t media_codec_type;
    115 	uint8_t data[0];
    116 } __attribute__ ((packed));
    117 
    118 #else
    119 #error "Unknown byte order"
    120 #endif
    121 
    122 typedef void (*avdtp_session_state_cb) (struct audio_device *dev,
    123 					struct avdtp *session,
    124 					avdtp_session_state_t old_state,
    125 					avdtp_session_state_t new_state,
    126 					void *user_data);
    127 
    128 typedef void (*avdtp_stream_state_cb) (struct avdtp_stream *stream,
    129 					avdtp_state_t old_state,
    130 					avdtp_state_t new_state,
    131 					struct avdtp_error *err,
    132 					void *user_data);
    133 
    134 /* Callbacks for when a reply is received to a command that we sent */
    135 struct avdtp_sep_cfm {
    136 	void (*set_configuration) (struct avdtp *session,
    137 					struct avdtp_local_sep *lsep,
    138 					struct avdtp_stream *stream,
    139 					struct avdtp_error *err,
    140 					void *user_data);
    141 	void (*get_configuration) (struct avdtp *session,
    142 					struct avdtp_local_sep *lsep,
    143 					struct avdtp_stream *stream,
    144 					struct avdtp_error *err,
    145 					void *user_data);
    146 	void (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
    147 			struct avdtp_stream *stream, struct avdtp_error *err,
    148 			void *user_data);
    149 	void (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
    150 			struct avdtp_stream *stream, struct avdtp_error *err,
    151 			void *user_data);
    152 	void (*suspend) (struct avdtp *session, struct avdtp_local_sep *lsep,
    153 				struct avdtp_stream *stream,
    154 				struct avdtp_error *err, void *user_data);
    155 	void (*close) (struct avdtp *session, struct avdtp_local_sep *lsep,
    156 				struct avdtp_stream *stream,
    157 				struct avdtp_error *err, void *user_data);
    158 	void (*abort) (struct avdtp *session, struct avdtp_local_sep *lsep,
    159 				struct avdtp_stream *stream,
    160 				struct avdtp_error *err, void *user_data);
    161 	void (*reconfigure) (struct avdtp *session,
    162 				struct avdtp_local_sep *lsep,
    163 				struct avdtp_stream *stream,
    164 				struct avdtp_error *err, void *user_data);
    165 };
    166 
    167 /* Callbacks for indicating when we received a new command. The return value
    168  * indicates whether the command should be rejected or accepted */
    169 struct avdtp_sep_ind {
    170 	gboolean (*get_capability) (struct avdtp *session,
    171 					struct avdtp_local_sep *sep,
    172 					GSList **caps, uint8_t *err,
    173 					void *user_data);
    174 	gboolean (*set_configuration) (struct avdtp *session,
    175 					struct avdtp_local_sep *lsep,
    176 					struct avdtp_stream *stream,
    177 					GSList *caps, uint8_t *err,
    178 					uint8_t *category, void *user_data);
    179 	gboolean (*get_configuration) (struct avdtp *session,
    180 					struct avdtp_local_sep *lsep,
    181 					uint8_t *err, void *user_data);
    182 	gboolean (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
    183 				struct avdtp_stream *stream, uint8_t *err,
    184 				void *user_data);
    185 	gboolean (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
    186 				struct avdtp_stream *stream, uint8_t *err,
    187 				void *user_data);
    188 	gboolean (*suspend) (struct avdtp *session,
    189 				struct avdtp_local_sep *sep,
    190 				struct avdtp_stream *stream, uint8_t *err,
    191 				void *user_data);
    192 	gboolean (*close) (struct avdtp *session, struct avdtp_local_sep *sep,
    193 				struct avdtp_stream *stream, uint8_t *err,
    194 				void *user_data);
    195 	gboolean (*abort) (struct avdtp *session, struct avdtp_local_sep *sep,
    196 				struct avdtp_stream *stream, uint8_t *err,
    197 				void *user_data);
    198 	gboolean (*reconfigure) (struct avdtp *session,
    199 					struct avdtp_local_sep *lsep,
    200 					uint8_t *err, void *user_data);
    201 };
    202 
    203 typedef void (*avdtp_discover_cb_t) (struct avdtp *session, GSList *seps,
    204 					struct avdtp_error *err, void *user_data);
    205 
    206 struct avdtp *avdtp_get(bdaddr_t *src, bdaddr_t *dst);
    207 
    208 void avdtp_unref(struct avdtp *session);
    209 struct avdtp *avdtp_ref(struct avdtp *session);
    210 
    211 gboolean avdtp_is_connected(const bdaddr_t *src, const bdaddr_t *dst);
    212 
    213 struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
    214 							void *data, int size);
    215 
    216 struct avdtp_remote_sep *avdtp_get_remote_sep(struct avdtp *session,
    217 						uint8_t seid);
    218 
    219 uint8_t avdtp_get_seid(struct avdtp_remote_sep *sep);
    220 
    221 uint8_t avdtp_get_type(struct avdtp_remote_sep *sep);
    222 
    223 struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep);
    224 
    225 struct avdtp_stream *avdtp_get_stream(struct avdtp_remote_sep *sep);
    226 
    227 int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
    228 			void *user_data);
    229 
    230 gboolean avdtp_has_stream(struct avdtp *session, struct avdtp_stream *stream);
    231 
    232 unsigned int avdtp_stream_add_cb(struct avdtp *session,
    233 					struct avdtp_stream *stream,
    234 					avdtp_stream_state_cb cb, void *data);
    235 gboolean avdtp_stream_remove_cb(struct avdtp *session,
    236 				struct avdtp_stream *stream,
    237 				unsigned int id);
    238 
    239 gboolean avdtp_stream_get_transport(struct avdtp_stream *stream, int *sock,
    240 					uint16_t *imtu, uint16_t *omtu,
    241 					GSList **caps);
    242 struct avdtp_service_capability *avdtp_stream_get_codec(
    243 						struct avdtp_stream *stream);
    244 gboolean avdtp_stream_has_capability(struct avdtp_stream *stream,
    245 				struct avdtp_service_capability *cap);
    246 gboolean avdtp_stream_has_capabilities(struct avdtp_stream *stream,
    247 					GSList *caps);
    248 
    249 unsigned int avdtp_add_state_cb(avdtp_session_state_cb cb, void *user_data);
    250 
    251 gboolean avdtp_remove_state_cb(unsigned int id);
    252 
    253 int avdtp_set_configuration(struct avdtp *session,
    254 				struct avdtp_remote_sep *rsep,
    255 				struct avdtp_local_sep *lsep,
    256 				GSList *caps,
    257 				struct avdtp_stream **stream);
    258 
    259 int avdtp_get_configuration(struct avdtp *session,
    260 				struct avdtp_stream *stream);
    261 
    262 int avdtp_open(struct avdtp *session, struct avdtp_stream *stream);
    263 int avdtp_reconfigure(struct avdtp *session, GSList *caps,
    264 			struct avdtp_stream *stream);
    265 int avdtp_start(struct avdtp *session, struct avdtp_stream *stream);
    266 int avdtp_suspend(struct avdtp *session, struct avdtp_stream *stream);
    267 int avdtp_close(struct avdtp *session, struct avdtp_stream *stream);
    268 int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
    269 
    270 struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
    271 						uint8_t media_type,
    272 						uint8_t codec_type,
    273 						struct avdtp_sep_ind *ind,
    274 						struct avdtp_sep_cfm *cfm,
    275 						void *user_data);
    276 
    277 /* Find a matching pair of local and remote SEP ID's */
    278 int avdtp_get_seps(struct avdtp *session, uint8_t type, uint8_t media,
    279 			uint8_t codec, struct avdtp_local_sep **lsep,
    280 			struct avdtp_remote_sep **rsep);
    281 
    282 int avdtp_unregister_sep(struct avdtp_local_sep *sep);
    283 
    284 avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep);
    285 
    286 void avdtp_error_init(struct avdtp_error *err, uint8_t type, int id);
    287 const char *avdtp_strerror(struct avdtp_error *err);
    288 avdtp_error_type_t avdtp_error_type(struct avdtp_error *err);
    289 int avdtp_error_error_code(struct avdtp_error *err);
    290 int avdtp_error_posix_errno(struct avdtp_error *err);
    291 
    292 void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst);
    293 
    294 void avdtp_set_auto_disconnect(struct avdtp *session, gboolean auto_dc);
    295 gboolean avdtp_stream_setup_active(struct avdtp *session);
    296 
    297 int avdtp_init(const bdaddr_t *src, GKeyFile *config);
    298 void avdtp_exit(const bdaddr_t *src);
    299