1 /** @file 2 * @brief Audio Video Remote Control Profile header. 3 */ 4 5 /* 6 * Copyright (c) 2015-2016 Intel Corporation 7 * Copyright (C) 2024 Xiaomi Corporation 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 */ 11 12 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AVRCP_H_ 13 #define ZEPHYR_INCLUDE_BLUETOOTH_AVRCP_H_ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** @brief AV/C command types */ 20 typedef enum __packed { 21 BT_AVRCP_CTYPE_CONTROL = 0x0, 22 BT_AVRCP_CTYPE_STATUS = 0x1, 23 BT_AVRCP_CTYPE_SPECIFIC_INQUIRY = 0x2, 24 BT_AVRCP_CTYPE_NOTIFY = 0x3, 25 BT_AVRCP_CTYPE_GENERAL_INQUIRY = 0x4, 26 } bt_avrcp_ctype_t; 27 28 /** @brief AV/C response codes */ 29 typedef enum __packed { 30 BT_AVRCP_RSP_NOT_IMPLEMENTED = 0x8, 31 BT_AVRCP_RSP_ACCEPTED = 0x9, 32 BT_AVRCP_RSP_REJECTED = 0xa, 33 BT_AVRCP_RSP_IN_TRANSITION = 0xb, 34 BT_AVRCP_RSP_IMPLEMENTED = 0xc, /**< For SPECIFIC_INQUIRY and GENERAL_INQUIRY commands */ 35 BT_AVRCP_RSP_STABLE = 0xc, /**< For STATUS commands */ 36 BT_AVRCP_RSP_CHANGED = 0xd, 37 BT_AVRCP_RSP_INTERIM = 0xf, 38 } bt_avrcp_rsp_t; 39 40 /** @brief AV/C operation ids used in AVRCP passthrough commands */ 41 typedef enum __packed { 42 BT_AVRCP_OPID_SELECT = 0x00, 43 BT_AVRCP_OPID_UP = 0x01, 44 BT_AVRCP_OPID_DOWN = 0x02, 45 BT_AVRCP_OPID_LEFT = 0x03, 46 BT_AVRCP_OPID_RIGHT = 0x04, 47 BT_AVRCP_OPID_RIGHT_UP = 0x05, 48 BT_AVRCP_OPID_RIGHT_DOWN = 0x06, 49 BT_AVRCP_OPID_LEFT_UP = 0x07, 50 BT_AVRCP_OPID_LEFT_DOWN = 0x08, 51 BT_AVRCP_OPID_ROOT_MENU = 0x09, 52 BT_AVRCP_OPID_SETUP_MENU = 0x0a, 53 BT_AVRCP_OPID_CONTENTS_MENU = 0x0b, 54 BT_AVRCP_OPID_FAVORITE_MENU = 0x0c, 55 BT_AVRCP_OPID_EXIT = 0x0d, 56 57 BT_AVRCP_OPID_0 = 0x20, 58 BT_AVRCP_OPID_1 = 0x21, 59 BT_AVRCP_OPID_2 = 0x22, 60 BT_AVRCP_OPID_3 = 0x23, 61 BT_AVRCP_OPID_4 = 0x24, 62 BT_AVRCP_OPID_5 = 0x25, 63 BT_AVRCP_OPID_6 = 0x26, 64 BT_AVRCP_OPID_7 = 0x27, 65 BT_AVRCP_OPID_8 = 0x28, 66 BT_AVRCP_OPID_9 = 0x29, 67 BT_AVRCP_OPID_DOT = 0x2a, 68 BT_AVRCP_OPID_ENTER = 0x2b, 69 BT_AVRCP_OPID_CLEAR = 0x2c, 70 71 BT_AVRCP_OPID_CHANNEL_UP = 0x30, 72 BT_AVRCP_OPID_CHANNEL_DOWN = 0x31, 73 BT_AVRCP_OPID_PREVIOUS_CHANNEL = 0x32, 74 BT_AVRCP_OPID_SOUND_SELECT = 0x33, 75 BT_AVRCP_OPID_INPUT_SELECT = 0x34, 76 BT_AVRCP_OPID_DISPLAY_INFORMATION = 0x35, 77 BT_AVRCP_OPID_HELP = 0x36, 78 BT_AVRCP_OPID_PAGE_UP = 0x37, 79 BT_AVRCP_OPID_PAGE_DOWN = 0x38, 80 81 BT_AVRCP_OPID_POWER = 0x40, 82 BT_AVRCP_OPID_VOLUME_UP = 0x41, 83 BT_AVRCP_OPID_VOLUME_DOWN = 0x42, 84 BT_AVRCP_OPID_MUTE = 0x43, 85 BT_AVRCP_OPID_PLAY = 0x44, 86 BT_AVRCP_OPID_STOP = 0x45, 87 BT_AVRCP_OPID_PAUSE = 0x46, 88 BT_AVRCP_OPID_RECORD = 0x47, 89 BT_AVRCP_OPID_REWIND = 0x48, 90 BT_AVRCP_OPID_FAST_FORWARD = 0x49, 91 BT_AVRCP_OPID_EJECT = 0x4a, 92 BT_AVRCP_OPID_FORWARD = 0x4b, 93 BT_AVRCP_OPID_BACKWARD = 0x4c, 94 95 BT_AVRCP_OPID_ANGLE = 0x50, 96 BT_AVRCP_OPID_SUBPICTURE = 0x51, 97 98 BT_AVRCP_OPID_F1 = 0x71, 99 BT_AVRCP_OPID_F2 = 0x72, 100 BT_AVRCP_OPID_F3 = 0x73, 101 BT_AVRCP_OPID_F4 = 0x74, 102 BT_AVRCP_OPID_F5 = 0x75, 103 BT_AVRCP_OPID_VENDOR_UNIQUE = 0x7e, 104 } bt_avrcp_opid_t; 105 106 /** @brief AVRCP button state flag */ 107 typedef enum __packed { 108 BT_AVRCP_BUTTON_PRESSED = 0, 109 BT_AVRCP_BUTTON_RELEASED = 1, 110 } bt_avrcp_button_state_t; 111 112 /** @brief AVRCP structure */ 113 struct bt_avrcp; 114 115 struct bt_avrcp_unit_info_rsp { 116 uint8_t unit_type; 117 uint32_t company_id; 118 }; 119 120 struct bt_avrcp_subunit_info_rsp { 121 uint8_t subunit_type; 122 uint8_t max_subunit_id; 123 const uint8_t *extended_subunit_type; /**< contains max_subunit_id items */ 124 const uint8_t *extended_subunit_id; /**< contains max_subunit_id items */ 125 }; 126 127 struct bt_avrcp_passthrough_rsp { 128 uint8_t response; /**< bt_avrcp_rsp_t */ 129 uint8_t operation_id; /**< bt_avrcp_opid_t */ 130 uint8_t state; /**< bt_avrcp_button_state_t */ 131 uint8_t len; 132 const uint8_t *payload; 133 }; 134 135 struct bt_avrcp_cb { 136 /** @brief An AVRCP connection has been established. 137 * 138 * This callback notifies the application of an avrcp connection, 139 * i.e., an AVCTP L2CAP connection. 140 * 141 * @param avrcp AVRCP connection object. 142 */ 143 void (*connected)(struct bt_avrcp *avrcp); 144 145 /** @brief An AVRCP connection has been disconnected. 146 * 147 * This callback notifies the application that an avrcp connection 148 * has been disconnected. 149 * 150 * @param avrcp AVRCP connection object. 151 */ 152 void (*disconnected)(struct bt_avrcp *avrcp); 153 154 /** @brief Callback function for bt_avrcp_get_unit_info(). 155 * 156 * Called when the get unit info process is completed. 157 * 158 * @param avrcp AVRCP connection object. 159 * @param rsp The response for UNIT INFO command. 160 */ 161 void (*unit_info_rsp)(struct bt_avrcp *avrcp, struct bt_avrcp_unit_info_rsp *rsp); 162 163 /** @brief Callback function for bt_avrcp_get_subunit_info(). 164 * 165 * Called when the get subunit info process is completed. 166 * 167 * @param avrcp AVRCP connection object. 168 * @param rsp The response for SUBUNIT INFO command. 169 */ 170 void (*subunit_info_rsp)(struct bt_avrcp *avrcp, struct bt_avrcp_subunit_info_rsp *rsp); 171 172 /** @brief Callback function for bt_avrcp_passthrough(). 173 * 174 * Called when a passthrough response is received. 175 * 176 * @param avrcp AVRCP connection object. 177 * @param rsp The response for PASS THROUGH command. 178 */ 179 void (*passthrough_rsp)(struct bt_avrcp *avrcp, struct bt_avrcp_passthrough_rsp *rsp); 180 }; 181 182 /** @brief Connect AVRCP. 183 * 184 * This function is to be called after the conn parameter is obtained by 185 * performing a GAP procedure. The API is to be used to establish AVRCP 186 * connection between devices. 187 * 188 * @param conn Pointer to bt_conn structure. 189 * 190 * @return pointer to struct bt_avrcp in case of success or NULL in case 191 * of error. 192 */ 193 struct bt_avrcp *bt_avrcp_connect(struct bt_conn *conn); 194 195 /** @brief Disconnect AVRCP. 196 * 197 * This function close AVCTP L2CAP connection. 198 * 199 * @param avrcp The AVRCP instance. 200 * 201 * @return 0 in case of success or error code in case of error. 202 */ 203 int bt_avrcp_disconnect(struct bt_avrcp *avrcp); 204 205 /** @brief Register callback. 206 * 207 * Register AVRCP callbacks to monitor the state and interact with the remote device. 208 * 209 * @param cb The callback function. 210 * 211 * @return 0 in case of success or error code in case of error. 212 */ 213 int bt_avrcp_register_cb(const struct bt_avrcp_cb *cb); 214 215 /** @brief Get AVRCP Unit Info. 216 * 217 * This function obtains information that pertains to the AV/C unit as a whole. 218 * 219 * @param avrcp The AVRCP instance. 220 * 221 * @return 0 in case of success or error code in case of error. 222 */ 223 int bt_avrcp_get_unit_info(struct bt_avrcp *avrcp); 224 225 /** @brief Get AVRCP Subunit Info. 226 * 227 * This function obtains information about the subunit(s) of an AV/C unit. A device with AVRCP 228 * may support other subunits than the panel subunit if other profiles co-exist in the device. 229 * 230 * @param avrcp The AVRCP instance. 231 * 232 * @return 0 in case of success or error code in case of error. 233 */ 234 int bt_avrcp_get_subunit_info(struct bt_avrcp *avrcp); 235 236 /** @brief Send AVRCP Pass Through command. 237 * 238 * This function send a pass through command to the remote device. Passsthhrough command is used 239 * to transfer user operation information from a CT to Panel subunit of TG. 240 * 241 * @param avrcp The AVRCP instance. 242 * @param operation_id The user operation id. 243 * @param state The button state. 244 * @param payload The payload of the pass through command. Should not be NULL if len is not zero. 245 * @param len The length of the payload. 246 * 247 * @return 0 in case of success or error code in case of error. 248 */ 249 int bt_avrcp_passthrough(struct bt_avrcp *avrcp, bt_avrcp_opid_t operation_id, 250 bt_avrcp_button_state_t state, const uint8_t *payload, uint8_t len); 251 252 #ifdef __cplusplus 253 } 254 #endif 255 256 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AVRCP_H_ */ 257