avdtp.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2006-2010 Nokia Corporation
  7. * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
  8. *
  9. *
  10. */
  11. typedef enum {
  12. AVDTP_SESSION_STATE_DISCONNECTED,
  13. AVDTP_SESSION_STATE_CONNECTING,
  14. AVDTP_SESSION_STATE_CONNECTED
  15. } avdtp_session_state_t;
  16. struct avdtp;
  17. struct avdtp_server;
  18. struct avdtp_stream;
  19. struct avdtp_local_sep;
  20. struct avdtp_remote_sep;
  21. struct avdtp_error {
  22. uint8_t category;
  23. union {
  24. uint8_t error_code;
  25. int posix_errno;
  26. } err;
  27. };
  28. /* SEP capability categories */
  29. #define AVDTP_MEDIA_TRANSPORT 0x01
  30. #define AVDTP_REPORTING 0x02
  31. #define AVDTP_RECOVERY 0x03
  32. #define AVDTP_CONTENT_PROTECTION 0x04
  33. #define AVDTP_HEADER_COMPRESSION 0x05
  34. #define AVDTP_MULTIPLEXING 0x06
  35. #define AVDTP_MEDIA_CODEC 0x07
  36. #define AVDTP_DELAY_REPORTING 0x08
  37. #define AVDTP_ERRNO 0xff
  38. /* AVDTP error definitions */
  39. #define AVDTP_BAD_HEADER_FORMAT 0x01
  40. #define AVDTP_BAD_LENGTH 0x11
  41. #define AVDTP_BAD_ACP_SEID 0x12
  42. #define AVDTP_SEP_IN_USE 0x13
  43. #define AVDTP_SEP_NOT_IN_USE 0x14
  44. #define AVDTP_BAD_SERV_CATEGORY 0x17
  45. #define AVDTP_BAD_PAYLOAD_FORMAT 0x18
  46. #define AVDTP_NOT_SUPPORTED_COMMAND 0x19
  47. #define AVDTP_INVALID_CAPABILITIES 0x1A
  48. #define AVDTP_BAD_RECOVERY_TYPE 0x22
  49. #define AVDTP_BAD_MEDIA_TRANSPORT_FORMAT 0x23
  50. #define AVDTP_BAD_RECOVERY_FORMAT 0x25
  51. #define AVDTP_BAD_ROHC_FORMAT 0x26
  52. #define AVDTP_BAD_CP_FORMAT 0x27
  53. #define AVDTP_BAD_MULTIPLEXING_FORMAT 0x28
  54. #define AVDTP_UNSUPPORTED_CONFIGURATION 0x29
  55. #define AVDTP_BAD_STATE 0x31
  56. /* SEP types definitions */
  57. #define AVDTP_SEP_TYPE_SOURCE 0x00
  58. #define AVDTP_SEP_TYPE_SINK 0x01
  59. /* Media types definitions */
  60. #define AVDTP_MEDIA_TYPE_AUDIO 0x00
  61. #define AVDTP_MEDIA_TYPE_VIDEO 0x01
  62. #define AVDTP_MEDIA_TYPE_MULTIMEDIA 0x02
  63. typedef enum {
  64. AVDTP_STATE_IDLE,
  65. AVDTP_STATE_CONFIGURED,
  66. AVDTP_STATE_OPEN,
  67. AVDTP_STATE_STREAMING,
  68. AVDTP_STATE_CLOSING,
  69. AVDTP_STATE_ABORTING,
  70. } avdtp_state_t;
  71. struct avdtp_service_capability {
  72. uint8_t category;
  73. uint8_t length;
  74. uint8_t data[0];
  75. } __attribute__ ((packed));
  76. #if __BYTE_ORDER == __LITTLE_ENDIAN
  77. struct avdtp_media_codec_capability {
  78. uint8_t rfa0:4;
  79. uint8_t media_type:4;
  80. uint8_t media_codec_type;
  81. uint8_t data[0];
  82. } __attribute__ ((packed));
  83. #elif __BYTE_ORDER == __BIG_ENDIAN
  84. struct avdtp_media_codec_capability {
  85. uint8_t media_type:4;
  86. uint8_t rfa0:4;
  87. uint8_t media_codec_type;
  88. uint8_t data[0];
  89. } __attribute__ ((packed));
  90. #else
  91. #error "Unknown byte order"
  92. #endif
  93. typedef void (*avdtp_session_state_cb) (struct btd_device *dev,
  94. struct avdtp *session,
  95. avdtp_session_state_t old_state,
  96. avdtp_session_state_t new_state,
  97. void *user_data);
  98. typedef void (*avdtp_stream_state_cb) (struct avdtp_stream *stream,
  99. avdtp_state_t old_state,
  100. avdtp_state_t new_state,
  101. struct avdtp_error *err,
  102. void *user_data);
  103. typedef void (*avdtp_set_configuration_cb) (struct avdtp *session,
  104. struct avdtp_stream *stream,
  105. struct avdtp_error *err);
  106. /* Callbacks for when a reply is received to a command that we sent */
  107. struct avdtp_sep_cfm {
  108. void (*set_configuration) (struct avdtp *session,
  109. struct avdtp_local_sep *lsep,
  110. struct avdtp_stream *stream,
  111. struct avdtp_error *err,
  112. void *user_data);
  113. void (*get_configuration) (struct avdtp *session,
  114. struct avdtp_local_sep *lsep,
  115. struct avdtp_stream *stream,
  116. struct avdtp_error *err,
  117. void *user_data);
  118. void (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
  119. struct avdtp_stream *stream, struct avdtp_error *err,
  120. void *user_data);
  121. void (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
  122. struct avdtp_stream *stream, struct avdtp_error *err,
  123. void *user_data);
  124. void (*suspend) (struct avdtp *session, struct avdtp_local_sep *lsep,
  125. struct avdtp_stream *stream,
  126. struct avdtp_error *err, void *user_data);
  127. void (*close) (struct avdtp *session, struct avdtp_local_sep *lsep,
  128. struct avdtp_stream *stream,
  129. struct avdtp_error *err, void *user_data);
  130. void (*abort) (struct avdtp *session, struct avdtp_local_sep *lsep,
  131. struct avdtp_stream *stream,
  132. struct avdtp_error *err, void *user_data);
  133. void (*reconfigure) (struct avdtp *session,
  134. struct avdtp_local_sep *lsep,
  135. struct avdtp_stream *stream,
  136. struct avdtp_error *err, void *user_data);
  137. void (*delay_report) (struct avdtp *session, struct avdtp_local_sep *lsep,
  138. struct avdtp_stream *stream,
  139. struct avdtp_error *err, void *user_data);
  140. };
  141. /* Callbacks for indicating when we received a new command. The return value
  142. * indicates whether the command should be rejected or accepted */
  143. struct avdtp_sep_ind {
  144. gboolean (*match_codec) (struct avdtp *session,
  145. struct avdtp_media_codec_capability *codec,
  146. void *user_data);
  147. gboolean (*get_capability) (struct avdtp *session,
  148. struct avdtp_local_sep *sep,
  149. gboolean get_all,
  150. GSList **caps, uint8_t *err,
  151. void *user_data);
  152. gboolean (*set_configuration) (struct avdtp *session,
  153. struct avdtp_local_sep *lsep,
  154. struct avdtp_stream *stream,
  155. GSList *caps,
  156. avdtp_set_configuration_cb cb,
  157. void *user_data);
  158. gboolean (*get_configuration) (struct avdtp *session,
  159. struct avdtp_local_sep *lsep,
  160. uint8_t *err, void *user_data);
  161. gboolean (*open) (struct avdtp *session, struct avdtp_local_sep *lsep,
  162. struct avdtp_stream *stream, uint8_t *err,
  163. void *user_data);
  164. gboolean (*start) (struct avdtp *session, struct avdtp_local_sep *lsep,
  165. struct avdtp_stream *stream, uint8_t *err,
  166. void *user_data);
  167. gboolean (*suspend) (struct avdtp *session,
  168. struct avdtp_local_sep *sep,
  169. struct avdtp_stream *stream, uint8_t *err,
  170. void *user_data);
  171. gboolean (*close) (struct avdtp *session, struct avdtp_local_sep *sep,
  172. struct avdtp_stream *stream, uint8_t *err,
  173. void *user_data);
  174. void (*abort) (struct avdtp *session, struct avdtp_local_sep *sep,
  175. struct avdtp_stream *stream, uint8_t *err,
  176. void *user_data);
  177. gboolean (*reconfigure) (struct avdtp *session,
  178. struct avdtp_local_sep *lsep,
  179. uint8_t *err, void *user_data);
  180. gboolean (*delayreport) (struct avdtp *session,
  181. struct avdtp_local_sep *lsep,
  182. uint8_t rseid, uint16_t delay,
  183. uint8_t *err, void *user_data);
  184. };
  185. typedef void (*avdtp_discover_cb_t) (struct avdtp *session, GSList *seps,
  186. struct avdtp_error *err, void *user_data);
  187. void avdtp_unref(struct avdtp *session);
  188. struct avdtp *avdtp_ref(struct avdtp *session);
  189. struct avdtp_service_capability *avdtp_service_cap_new(uint8_t category,
  190. void *data, int size);
  191. struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
  192. uint8_t seid,
  193. uint8_t type,
  194. GSList *caps,
  195. bool delay_reporting);
  196. int avdtp_unregister_remote_sep(struct avdtp *session,
  197. struct avdtp_remote_sep *rsep);
  198. typedef void (*avdtp_remote_sep_destroy_t)(void *user_data);
  199. void avdtp_remote_sep_set_destroy(struct avdtp_remote_sep *sep, void *user_data,
  200. avdtp_remote_sep_destroy_t destroy);
  201. uint8_t avdtp_get_seid(struct avdtp_remote_sep *sep);
  202. uint8_t avdtp_get_type(struct avdtp_remote_sep *sep);
  203. struct avdtp_service_capability *avdtp_get_codec(struct avdtp_remote_sep *sep);
  204. bool avdtp_get_delay_reporting(struct avdtp_remote_sep *sep);
  205. int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
  206. void *user_data);
  207. gboolean avdtp_has_stream(struct avdtp *session, struct avdtp_stream *stream);
  208. unsigned int avdtp_stream_add_cb(struct avdtp *session,
  209. struct avdtp_stream *stream,
  210. avdtp_stream_state_cb cb, void *data);
  211. gboolean avdtp_stream_remove_cb(struct avdtp *session,
  212. struct avdtp_stream *stream,
  213. unsigned int id);
  214. gboolean avdtp_stream_set_transport(struct avdtp_stream *stream, int fd,
  215. size_t imtu, size_t omtu);
  216. gboolean avdtp_stream_get_transport(struct avdtp_stream *stream, int *sock,
  217. uint16_t *imtu, uint16_t *omtu,
  218. GSList **caps);
  219. struct avdtp_service_capability *avdtp_stream_get_codec(
  220. struct avdtp_stream *stream);
  221. gboolean avdtp_stream_has_capabilities(struct avdtp_stream *stream,
  222. GSList *caps);
  223. struct avdtp_remote_sep *avdtp_stream_get_remote_sep(
  224. struct avdtp_stream *stream);
  225. unsigned int avdtp_add_state_cb(struct btd_device *dev,
  226. avdtp_session_state_cb cb, void *user_data);
  227. gboolean avdtp_remove_state_cb(unsigned int id);
  228. int avdtp_set_configuration(struct avdtp *session,
  229. struct avdtp_remote_sep *rsep,
  230. struct avdtp_local_sep *lsep,
  231. GSList *caps,
  232. struct avdtp_stream **stream);
  233. int avdtp_get_configuration(struct avdtp *session,
  234. struct avdtp_stream *stream);
  235. int avdtp_open(struct avdtp *session, struct avdtp_stream *stream);
  236. int avdtp_start(struct avdtp *session, struct avdtp_stream *stream);
  237. int avdtp_suspend(struct avdtp *session, struct avdtp_stream *stream);
  238. int avdtp_close(struct avdtp *session, struct avdtp_stream *stream,
  239. gboolean immediate);
  240. int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream);
  241. int avdtp_delay_report(struct avdtp *session, struct avdtp_stream *stream,
  242. uint16_t delay);
  243. struct avdtp_local_sep *avdtp_register_sep(struct queue *lseps,
  244. uint64_t *seid_pool,
  245. uint8_t type,
  246. uint8_t media_type,
  247. uint8_t codec_type,
  248. gboolean delay_reporting,
  249. struct avdtp_sep_ind *ind,
  250. struct avdtp_sep_cfm *cfm,
  251. void *user_data);
  252. /* Find a matching pair of local and remote SEP ID's */
  253. struct avdtp_remote_sep *avdtp_find_remote_sep(struct avdtp *session,
  254. struct avdtp_local_sep *lsep);
  255. int avdtp_unregister_sep(struct queue *lseps, uint64_t *seid_pool,
  256. struct avdtp_local_sep *sep);
  257. avdtp_state_t avdtp_sep_get_state(struct avdtp_local_sep *sep);
  258. uint8_t avdtp_sep_get_seid(struct avdtp_local_sep *sep);
  259. void avdtp_error_init(struct avdtp_error *err, uint8_t type, int id);
  260. const char *avdtp_strerror(struct avdtp_error *err);
  261. uint8_t avdtp_error_category(struct avdtp_error *err);
  262. int avdtp_error_error_code(struct avdtp_error *err);
  263. int avdtp_error_posix_errno(struct avdtp_error *err);
  264. struct btd_adapter *avdtp_get_adapter(struct avdtp *session);
  265. struct btd_device *avdtp_get_device(struct avdtp *session);
  266. struct avdtp_server *avdtp_get_server(struct avdtp_local_sep *lsep);
  267. struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
  268. struct queue *lseps);
  269. uint16_t avdtp_get_version(struct avdtp *session);