avdtp.h 9.1 KB

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