1 /* 2 * avdtp_internal.h - avdtp handling 3 4 * Copyright (c) 2015-2016 Intel Corporation 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #include <bluetooth/avdtp.h> 10 11 /* @brief A2DP ROLE's */ 12 #define A2DP_SRC_ROLE 0x00 13 #define A2DP_SNK_ROLE 0x01 14 15 /* @brief AVDTP Role */ 16 #define BT_AVDTP_INT 0x00 17 #define BT_AVDTP_ACP 0x01 18 19 #define BT_L2CAP_PSM_AVDTP 0x0019 20 21 /* AVDTP SIGNAL HEADER - Packet Type*/ 22 #define BT_AVDTP_PACKET_TYPE_SINGLE 0x00 23 #define BT_AVDTP_PACKET_TYPE_START 0x01 24 #define BT_AVDTP_PACKET_TYPE_CONTINUE 0x02 25 #define BT_AVDTP_PACKET_TYPE_END 0x03 26 27 /* AVDTP SIGNAL HEADER - MESSAGE TYPE */ 28 #define BT_AVDTP_CMD 0x00 29 #define BT_AVDTP_GEN_REJECT 0x01 30 #define BT_AVDTP_ACCEPT 0x02 31 #define BT_AVDTP_REJECT 0x03 32 33 /* @brief AVDTP SIGNAL HEADER - Signal Identifier */ 34 #define BT_AVDTP_DISCOVER 0x01 35 #define BT_AVDTP_GET_CAPABILITIES 0x02 36 #define BT_AVDTP_SET_CONFIGURATION 0x03 37 #define BT_AVDTP_GET_CONFIGURATION 0x04 38 #define BT_AVDTP_RECONFIGURE 0x05 39 #define BT_AVDTP_OPEN 0x06 40 #define BT_AVDTP_START 0x07 41 #define BT_AVDTP_CLOSE 0x08 42 #define BT_AVDTP_SUSPEND 0x09 43 #define BT_AVDTP_ABORT 0x0a 44 #define BT_AVDTP_SECURITY_CONTROL 0x0b 45 #define BT_AVDTP_GET_ALL_CAPABILITIES 0x0c 46 #define BT_AVDTP_DELAYREPORT 0x0d 47 48 /* @brief AVDTP STREAM STATE */ 49 #define BT_AVDTP_STREAM_STATE_IDLE 0x01 50 #define BT_AVDTP_STREAM_STATE_CONFIGURED 0x02 51 #define BT_AVDTP_STREAM_STATE_OPEN 0x03 52 #define BT_AVDTP_STREAM_STATE_STREAMING 0x04 53 #define BT_AVDTP_STREAM_STATE_CLOSING 0x05 54 55 /* @brief AVDTP Media TYPE */ 56 #define BT_AVDTP_SERVICE_CAT_MEDIA_TRANSPORT 0x01 57 #define BT_AVDTP_SERVICE_CAT_REPORTING 0x02 58 #define BT_AVDTP_SERVICE_CAT_RECOVERY 0x03 59 #define BT_AVDTP_SERVICE_CAT_CONTENT_PROTECTION 0x04 60 #define BT_AVDTP_SERVICE_CAT_HDR_COMPRESSION 0x05 61 #define BT_AVDTP_SERVICE_CAT_MULTIPLEXING 0x06 62 #define BT_AVDTP_SERVICE_CAT_MEDIA_CODEC 0x07 63 #define BT_AVDTP_SERVICE_CAT_DELAYREPORTING 0x08 64 65 /* AVDTP Error Codes */ 66 #define BT_AVDTP_SUCCESS 0x00 67 #define BT_AVDTP_ERR_BAD_HDR_FORMAT 0x01 68 #define BT_AVDTP_ERR_BAD_LENGTH 0x11 69 #define BT_AVDTP_ERR_BAD_ACP_SEID 0x12 70 #define BT_AVDTP_ERR_SEP_IN_USE 0x13 71 #define BT_AVDTP_ERR_SEP_NOT_IN_USE 0x14 72 #define BT_AVDTP_ERR_BAD_SERV_CATEGORY 0x17 73 #define BT_AVDTP_ERR_BAD_PAYLOAD_FORMAT 0x18 74 #define BT_AVDTP_ERR_NOT_SUPPORTED_COMMAND 0x19 75 #define BT_AVDTP_ERR_INVALID_CAPABILITIES 0x1a 76 #define BT_AVDTP_ERR_BAD_RECOVERY_TYPE 0x22 77 #define BT_AVDTP_ERR_BAD_MEDIA_TRANSPORT_FORMAT 0x23 78 #define BT_AVDTP_ERR_BAD_RECOVERY_FORMAT 0x25 79 #define BT_AVDTP_ERR_BAD_ROHC_FORMAT 0x26 80 #define BT_AVDTP_ERR_BAD_CP_FORMAT 0x27 81 #define BT_AVDTP_ERR_BAD_MULTIPLEXING_FORMAT 0x28 82 #define BT_AVDTP_ERR_UNSUPPORTED_CONFIGURAION 0x29 83 #define BT_AVDTP_ERR_BAD_STATE 0x31 84 85 #define BT_AVDTP_MAX_MTU BT_L2CAP_RX_MTU 86 87 #define BT_AVDTP_MIN_SEID 0x01 88 #define BT_AVDTP_MAX_SEID 0x3E 89 90 struct bt_avdtp; 91 struct bt_avdtp_req; 92 93 typedef int (*bt_avdtp_func_t)(struct bt_avdtp *session, 94 struct bt_avdtp_req *req); 95 96 struct bt_avdtp_req { 97 u8_t sig; 98 u8_t tid; 99 bt_avdtp_func_t func; 100 struct k_delayed_work timeout_work; 101 }; 102 103 struct bt_avdtp_single_sig_hdr { 104 u8_t hdr; 105 u8_t signal_id; 106 } __packed; 107 108 #define BT_AVDTP_SIG_HDR_LEN sizeof(struct bt_avdtp_single_sig_hdr) 109 110 struct bt_avdtp_ind_cb { 111 /* 112 * discovery_ind; 113 * get_capabilities_ind; 114 * set_configuration_ind; 115 * open_ind; 116 * start_ind; 117 * suspend_ind; 118 * close_ind; 119 */ 120 }; 121 122 struct bt_avdtp_cap { 123 u8_t cat; 124 u8_t len; 125 u8_t data[0]; 126 }; 127 128 struct bt_avdtp_sep { 129 u8_t seid; 130 u8_t len; 131 struct bt_avdtp_cap caps[0]; 132 }; 133 134 struct bt_avdtp_discover_params { 135 struct bt_avdtp_req req; 136 u8_t status; 137 struct bt_avdtp_sep *caps; 138 }; 139 140 /** @brief Global AVDTP session structure. */ 141 struct bt_avdtp { 142 struct bt_l2cap_br_chan br_chan; 143 struct bt_avdtp_stream *streams; /* List of AV streams */ 144 struct bt_avdtp_req *req; 145 }; 146 147 struct bt_avdtp_event_cb { 148 struct bt_avdtp_ind_cb *ind; 149 int (*accept)(struct bt_conn *conn, struct bt_avdtp **session); 150 }; 151 152 /* Initialize AVDTP layer*/ 153 int bt_avdtp_init(void); 154 155 /* Application register with AVDTP layer */ 156 int bt_avdtp_register(struct bt_avdtp_event_cb *cb); 157 158 /* AVDTP connect */ 159 int bt_avdtp_connect(struct bt_conn *conn, struct bt_avdtp *session); 160 161 /* AVDTP disconnect */ 162 int bt_avdtp_disconnect(struct bt_avdtp *session); 163 164 /* AVDTP SEP register function */ 165 int bt_avdtp_register_sep(u8_t media_type, u8_t role, 166 struct bt_avdtp_seid_lsep *sep); 167 168 /* AVDTP Discover Request */ 169 int bt_avdtp_discover(struct bt_avdtp *session, 170 struct bt_avdtp_discover_params *param); 171