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_SESSION_STATE_DISCONNECTED,
     27 	AVDTP_SESSION_STATE_CONNECTING,
     28 	AVDTP_SESSION_STATE_CONNECTED
     29 } avdtp_session_state_t;
     30 
     31 struct avdtp;
     32 struct avdtp_stream;
     33 struct avdtp_local_sep;
     34 struct avdtp_remote_sep;
     35 struct avdtp_error {
     36 	uint8_t category;
     37 	union {
     38 		uint8_t error_code;
     39 		int posix_errno;
     40 	} err;
     41 };
     42 
     43 /* SEP capability categories */
     44 #define AVDTP_MEDIA_TRANSPORT			0x01
     45 #define AVDTP_REPORTING				0x02
     46 #define AVDTP_RECOVERY				0x03
     47 #define AVDTP_CONTENT_PROTECTION		0x04
     48 #define AVDTP_HEADER_COMPRESSION		0x05
     49 #define AVDTP_MULTIPLEXING			0x06
     50 #define AVDTP_MEDIA_CODEC			0x07
     51 #define AVDTP_DELAY_REPORTING			0x08
     52 #define AVDTP_ERRNO				0xff
     53 
     54 /* AVDTP error definitions */
     55 #define AVDTP_BAD_HEADER_FORMAT			0x01
     56 #define AVDTP_BAD_LENGTH			0x11
     57 #define AVDTP_BAD_ACP_SEID			0x12
     58 #define AVDTP_SEP_IN_USE			0x13
     59 #define AVDTP_SEP_NOT_IN_USE			0x14
     60 #define AVDTP_BAD_SERV_CATEGORY			0x17
     61 #define AVDTP_BAD_PAYLOAD_FORMAT		0x18
     62 #define AVDTP_NOT_SUPPORTED_COMMAND		0x19
     63 #define AVDTP_INVALID_CAPABILITIES		0x1A
     64 #define AVDTP_BAD_RECOVERY_TYPE			0x22
     65 #define AVDTP_BAD_MEDIA_TRANSPORT_FORMAT	0x23
     66 #define AVDTP_BAD_RECOVERY_FORMAT		0x25
     67 #define AVDTP_BAD_ROHC_FORMAT			0x26
     68 #define AVDTP_BAD_CP_FORMAT			0x27
     69 #define AVDTP_BAD_MULTIPLEXING_FORMAT		0x28
     70 #define AVDTP_UNSUPPORTED_CONFIGURATION		0x29
     71 #define AVDTP_BAD_STATE				0x31
     72 
     73 /* SEP types definitions */
     74 #define AVDTP_SEP_TYPE_SOURCE			0x00
     75 #define AVDTP_SEP_TYPE_SINK			0x01
     76 
     77 /* Media types definitions */
     78 #define AVDTP_MEDIA_TYPE_AUDIO			0x00
     79 #define AVDTP_MEDIA_TYPE_VIDEO			0x01
     80 #define AVDTP_MEDIA_TYPE_MULTIMEDIA		0x02
     81 
     82 typedef enum {
     83 	AVDTP_STATE_IDLE,
     84 	AVDTP_STATE_CONFIGURED,
     85 	AVDTP_STATE_OPEN,
     86 	AVDTP_STATE_STREAMING,
     87 	AVDTP_STATE_CLOSING,
     88 	AVDTP_STATE_ABORTING,
     89 } avdtp_state_t;
     90 
     91 struct avdtp_service_capability {
     92 	uint8_t category;
     93 	uint8_t length;
     94 	uint8_t data[0];
     95 } __attribute__ ((packed));
     96 
     97 #if __BYTE_ORDER == __LITTLE_ENDIAN
     98 
     99 struct avdtp_media_codec_capability {
    100 	uint8_t rfa0:4;
    101 	uint8_t media_type:4;
    102 	uint8_t media_codec_type;
    103 	uint8_t data[0];
    104 } __attribute__ ((packed));
    105 
    106 #elif __BYTE_ORDER == __BIG_ENDIAN
    107 
    108 struct avdtp_media_codec_capability {
    109 	uint8_t media_type:4;
    110 	uint8_t rfa0:4;
    111 	uint8_t media_codec_type;
    112 	uint8_t data[0];
    113 } __attribute__ ((packed));
    114 
    115 #else
    116 #error "Unknown byte order"
    117 #endif
    118 
    119 typedef void (*avdtp_session_state_cb) (struct audio_device *dev,
    120 					struct avdtp *session,
    121 					avdtp_session_state_t old_state,
    122 					avdtp_session_state_t new_state,
    123 					void *user_data);
    124 
    125 typedef void (*avdtp_stream_state_cb) (struct avdtp_stream *stream,
    126 					avdtp_state_t old_state,
    127 					avdtp_state_t new_state,
    128 					struct avdtp_error *err,
    129 					void *user_data);
    130 
    131 typedef void (*avdtp_set_configuration_cb) (struct avdtp *session,
    132 						struct avdtp_stream *stream,
    133 						struct avdtp_error *err);
    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,
    183 					avdtp_set_configuration_cb cb,
    184 					void *user_data);
    185 	gboolean (*get_configuration) (struct avdtp *session,
    186 					struct avdtp_local_sep *lsep,
    187 					uint8_t *err, void *user_data);
    188 	gboolean (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
    189 				struct avdtp_stream *stream, uint8_t *err,
    190 				void *user_data);
    191 	gboolean (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
    192 				struct avdtp_stream *stream, uint8_t *err,
    193 				void *user_data);
    194 	gboolean (*suspend) (struct avdtp *session,
    195 				struct avdtp_local_sep *sep,
    196 				struct avdtp_stream *stream, uint8_t *err,
    197 				void *user_data);
    198 	gboolean (*close) (struct avdtp *session, struct avdtp_local_sep *sep,
    199 				struct avdtp_stream *stream, uint8_t *err,
    200 				void *user_data);
    201 	gboolean (*abort) (struct avdtp *session, struct avdtp_local_sep *sep,
    202 				struct avdtp_stream *stream, uint8_t *err,
    203 				void *user_data);
    204 	gboolean (*reconfigure) (struct avdtp *session,
    205 					struct avdtp_local_sep *lsep,
    206 					uint8_t *err, void *user_data);
    207 	gboolean (*delayreport) (struct avdtp *session,
    208 					struct avdtp_local_sep *lsep,
    209 					uint8_t rseid, uint16_t delay,
    210 					uint8_t *err, void *user_data);
    211 };
    212 
    213 typedef void (*avdtp_discover_cb_t) (struct avdtp *session, GSList *seps,
    214 					struct avdtp_error *err, void *user_data);
    215 
    216 struct avdtp *avdtp_get(bdaddr_t *src, bdaddr_t *dst);
    217 
    218 void avdtp_unref(struct avdtp *session);
    219 struct avdtp *avdtp_ref(struct avdtp *session);
    220 
    221 gboolean avdtp_is_connected(const bdaddr_t *src, const bdaddr_t *dst);
    222 
    223 struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
    224 							void *data, int size);
    225 
    226 struct avdtp_remote_sep *avdtp_get_remote_sep(struct avdtp *session,
    227 						uint8_t seid);
    228 
    229 uint8_t avdtp_get_seid(struct avdtp_remote_sep *sep);
    230 
    231 uint8_t avdtp_get_type(struct avdtp_remote_sep *sep);
    232 
    233 struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep);
    234 
    235 gboolean avdtp_get_delay_reporting(struct avdtp_remote_sep *sep);
    236 
    237 struct avdtp_stream *avdtp_get_stream(struct avdtp_remote_sep *sep);
    238 
    239 int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
    240 			void *user_data);
    241 
    242 gboolean avdtp_has_stream(struct avdtp *session, struct avdtp_stream *stream);
    243 
    244 unsigned int avdtp_stream_add_cb(struct avdtp *session,
    245 					struct avdtp_stream *stream,
    246 					avdtp_stream_state_cb cb, void *data);
    247 gboolean avdtp_stream_remove_cb(struct avdtp *session,
    248 				struct avdtp_stream *stream,
    249 				unsigned int id);
    250 
    251 gboolean avdtp_stream_get_transport(struct avdtp_stream *stream, int *sock,
    252 					uint16_t *imtu, uint16_t *omtu,
    253 					GSList **caps);
    254 struct avdtp_service_capability *avdtp_stream_get_codec(
    255 						struct avdtp_stream *stream);
    256 gboolean avdtp_stream_has_capability(struct avdtp_stream *stream,
    257 				struct avdtp_service_capability *cap);
    258 gboolean avdtp_stream_has_capabilities(struct avdtp_stream *stream,
    259 					GSList *caps);
    260 struct avdtp_remote_sep *avdtp_stream_get_remote_sep(
    261 						struct avdtp_stream *stream);
    262 
    263 unsigned int avdtp_add_state_cb(avdtp_session_state_cb cb, void *user_data);
    264 
    265 gboolean avdtp_remove_state_cb(unsigned int id);
    266 
    267 int avdtp_set_configuration(struct avdtp *session,
    268 				struct avdtp_remote_sep *rsep,
    269 				struct avdtp_local_sep *lsep,
    270 				GSList *caps,
    271 				struct avdtp_stream **stream);
    272 
    273 int avdtp_get_configuration(struct avdtp *session,
    274 				struct avdtp_stream *stream);
    275 
    276 int avdtp_open(struct avdtp *session, struct avdtp_stream *stream);
    277 int avdtp_reconfigure(struct avdtp *session, GSList *caps,
    278 			struct avdtp_stream *stream);
    279 int avdtp_start(struct avdtp *session, struct avdtp_stream *stream);
    280 int avdtp_suspend(struct avdtp *session, struct avdtp_stream *stream);
    281 int avdtp_close(struct avdtp *session, struct avdtp_stream *stream,
    282 		gboolean immediate);
    283 int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
    284 int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
    285 							uint16_t delay);
    286 
    287 struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type,
    288 						uint8_t media_type,
    289 						uint8_t codec_type,
    290 						gboolean delay_reporting,
    291 						struct avdtp_sep_ind *ind,
    292 						struct avdtp_sep_cfm *cfm,
    293 						void *user_data);
    294 
    295 /* Find a matching pair of local and remote SEP ID's */
    296 struct avdtp_remote_sep *avdtp_find_remote_sep(struct avdtp *session,
    297 						struct avdtp_local_sep *lsep);
    298 
    299 int avdtp_unregister_sep(struct avdtp_local_sep *sep);
    300 
    301 avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep);
    302 
    303 void avdtp_error_init(struct avdtp_error *err, uint8_t type, int id);
    304 const char *avdtp_strerror(struct avdtp_error *err);
    305 uint8_t avdtp_error_category(struct avdtp_error *err);
    306 int avdtp_error_error_code(struct avdtp_error *err);
    307 int avdtp_error_posix_errno(struct avdtp_error *err);
    308 
    309 void avdtp_get_peers(struct avdtp *session, bdaddr_t *src, bdaddr_t *dst);
    310 
    311 void avdtp_set_auto_disconnect(struct avdtp *session, gboolean auto_dc);
    312 gboolean avdtp_stream_setup_active(struct avdtp *session);
    313 void avdtp_set_device_disconnect(struct avdtp *session, gboolean dev_dc);
    314 
    315 int avdtp_init(const bdaddr_t *src, GKeyFile *config, uint16_t *version);
    316 void avdtp_exit(const bdaddr_t *src);
    317