1 /** @file 2 * @brief Audio Video Remote Control Profile internal 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 #define AVCTP_VER_1_4 (0x0104u) 13 #define AVRCP_VER_1_6 (0x0106u) 14 15 #define AVRCP_CAT_1 BIT(0) /* Player/Recorder */ 16 #define AVRCP_CAT_2 BIT(1) /* Monitor/Amplifier */ 17 #define AVRCP_CAT_3 BIT(2) /* Tuner */ 18 #define AVRCP_CAT_4 BIT(3) /* Menu */ 19 20 #define AVRCP_SUBUNIT_PAGE (0) /* Fixed value according to AVRCP */ 21 #define AVRCP_SUBUNIT_EXTENSION_CODE (7) /* Fixed value according to TA Document 2001012 */ 22 #define BT_AVRCP_UNIT_INFO_CMD_SIZE (5) 23 #define BT_AVRCP_UNIT_INFO_RSP_SIZE (5) 24 #define BT_AVRCP_SUBUNIT_INFO_RSP_SIZE (5) 25 26 typedef enum __packed { 27 BT_AVRCP_SUBUNIT_ID_ZERO = 0x0, 28 BT_AVRCP_SUBUNIT_ID_IGNORE = 0x7, 29 } bt_avrcp_subunit_id_t; 30 31 typedef enum __packed { 32 BT_AVRCP_OPC_VENDOR_DEPENDENT = 0x0, 33 BT_AVRCP_OPC_UNIT_INFO = 0x30, 34 BT_AVRCP_OPC_SUBUNIT_INFO = 0x31, 35 BT_AVRCP_OPC_PASS_THROUGH = 0x7c, 36 } bt_avrcp_opcode_t; 37 38 typedef enum __packed { 39 BT_AVRVP_PKT_TYPE_SINGLE = 0b00, 40 BT_AVRVP_PKT_TYPE_START = 0b01, 41 BT_AVRVP_PKT_TYPE_CONTINUE = 0b10, 42 BT_AVRVP_PKT_TYPE_END = 0b11, 43 } bt_avrcp_pkt_type_t; 44 45 typedef enum __packed { 46 /** Capabilities */ 47 BT_AVRCP_PDU_ID_GET_CAPS = 0x10, 48 49 /** Player Application Settings */ 50 BT_AVRCP_PDU_ID_LIST_PLAYER_APP_SETTING_ATTRS = 0x11, 51 BT_AVRCP_PDU_ID_LIST_PLAYER_APP_SETTING_VALS = 0x12, 52 BT_AVRCP_PDU_ID_GET_CURR_PLAYER_APP_SETTING_VAL = 0x13, 53 BT_AVRCP_PDU_ID_SET_PLAYER_APP_SETTING_VAL = 0x14, 54 BT_AVRCP_PDU_ID_GET_PLAYER_APP_SETTING_ATTR_TEXT = 0x15, 55 BT_AVRCP_PDU_ID_GET_PLAYER_APP_SETTING_VAL_TEXT = 0x16, 56 BT_AVRCP_PDU_ID_INFORM_DISPLAYABLE_CHAR_SET = 0x17, 57 BT_AVRCP_PDU_ID_INFORM_BATT_STATUS_OF_CT = 0x18, 58 59 /** Metadata Attributes for Current Media Item */ 60 BT_AVRCP_PDU_ID_GET_ELEMENT_ATTRS = 0x20, 61 62 /** Notifications */ 63 BT_AVRCP_PDU_ID_GET_PLAY_STATUS = 0x30, 64 BT_AVRCP_PDU_ID_REGISTER_NOTIFICATION = 0x31, 65 BT_AVRCP_PDU_ID_EVT_PLAYBACK_STATUS_CHANGED = 0x31, 66 BT_AVRCP_PDU_ID_EVT_TRACK_CHANGED = 0x31, 67 BT_AVRCP_PDU_ID_EVT_TRACK_REACHED_END = 0x31, 68 BT_AVRCP_PDU_ID_EVT_TRACK_REACHED_START = 0x31, 69 BT_AVRCP_PDU_ID_EVT_PLAYBACK_POS_CHANGED = 0x31, 70 BT_AVRCP_PDU_ID_EVT_BATT_STATUS_CHANGED = 0x31, 71 BT_AVRCP_PDU_ID_EVT_SYSTEM_STATUS_CHANGED = 0x31, 72 BT_AVRCP_PDU_ID_EVT_PLAYER_APP_SETTING_CHANGED = 0x31, 73 BT_AVRCP_PDU_ID_EVT_VOLUME_CHANGED = 0x31, 74 BT_AVRCP_PDU_ID_EVT_ADDRESSED_PLAYER_CHANGED = 0x31, 75 BT_AVRCP_PDU_ID_EVT_AVAILABLE_PLAYERS_CHANGED = 0x31, 76 BT_AVRCP_PDU_ID_EVT_UIDS_CHANGED = 0x31, 77 78 /** Continuation */ 79 BT_AVRCP_PDU_ID_REQ_CONTINUING_RSP = 0x40, 80 BT_AVRCP_PDU_ID_ABORT_CONTINUING_RSP = 0x41, 81 82 /** Absolute Volume */ 83 BT_AVRCP_PDU_ID_SET_ABSOLUTE_VOLUME = 0x50, 84 85 /** Media Player Selection */ 86 BT_AVRCP_PDU_ID_SET_ADDRESSED_PLAYER = 0x60, 87 88 /** Browsing */ 89 BT_AVRCP_PDU_ID_SET_BROWSED_PLAYER = 0x70, 90 BT_AVRCP_PDU_ID_GET_FOLDER_ITEMS = 0x71, 91 BT_AVRCP_PDU_ID_CHANGE_PATH = 0x72, 92 BT_AVRCP_PDU_ID_GET_ITEM_ATTRS = 0x73, 93 BT_AVRCP_PDU_ID_PLAY_ITEM = 0x74, 94 BT_AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS = 0x75, 95 96 /** Search */ 97 BT_AVRCP_PDU_ID_SEARCH = 0x80, 98 99 /** Now Playing */ 100 BT_AVRCP_PDU_ID_ADD_TO_NOW_PLAYING = 0x90, 101 102 /** Error Response */ 103 BT_AVRCP_PDU_ID_GENERAL_REJECT = 0xa0, 104 } bt_avrcp_pdu_id_t; 105 106 struct bt_avrcp_req { 107 uint8_t tid; 108 uint8_t subunit; 109 uint8_t opcode; 110 }; 111 112 struct bt_avrcp_header { 113 uint8_t byte0; /**< [7:4]: RFA, [3:0]: Ctype */ 114 uint8_t byte1; /**< [7:3]: Subunit_type, [2:0]: Subunit_ID */ 115 uint8_t opcode; /**< Unit Info, Subunit Info, Vendor Dependent, or Pass Through */ 116 } __packed; 117 118 struct bt_avrcp_avc_pdu { 119 uint8_t pdu_id; 120 uint8_t pkt_type; /**< [7:2]: Reserved, [1:0]: Packet Type */ 121 uint16_t param_len; 122 uint8_t param[]; 123 } __packed; 124 125 /** The 4-bit command type or the 4-bit response code. */ 126 #define BT_AVRCP_HDR_GET_CTYPE_OR_RSP(hdr) FIELD_GET(GENMASK(3, 0), ((hdr)->byte0)) 127 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s address 128 * within the target. These fields enable the target to determine whether the command is 129 * addressed to the target unit, or to a specific subunit within the target. The values in these 130 * fields remain unchanged in the response frame. 131 */ 132 #define BT_AVRCP_HDR_GET_SUBUNIT_ID(hdr) FIELD_GET(GENMASK(2, 0), ((hdr)->byte1)) 133 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s address 134 * within the target. These fields enable the target to determine whether the command is 135 * addressed to the target unit, or to a specific subunit within the target. The values in these 136 * fields remain unchanged in the response frame. 137 */ 138 #define BT_AVRCP_HDR_GET_SUBUNIT_TYPE(hdr) FIELD_GET(GENMASK(7, 3), ((hdr)->byte1)) 139 140 /** The 4-bit command type or the 4-bit response code. */ 141 #define BT_AVRCP_HDR_SET_CTYPE_OR_RSP(hdr, ctype) \ 142 (hdr)->byte0 = (((hdr)->byte0) & ~GENMASK(3, 0)) | FIELD_PREP(GENMASK(3, 0), (ctype)) 143 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s address 144 * within the target. These fields enable the target to determine whether the command is 145 * addressed to the target unit, or to a specific subunit within the target. The values in these 146 * fields remain unchanged in the response frame. 147 */ 148 #define BT_AVRCP_HDR_SET_SUBUNIT_ID(hdr, subunit_id) \ 149 (hdr)->byte1 = (((hdr)->byte1) & ~GENMASK(2, 0)) | FIELD_PREP(GENMASK(2, 0), (subunit_id)) 150 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s address 151 * within the target. These fields enable the target to determine whether the command is 152 * addressed to the target unit, or to a specific subunit within the target. The values in these 153 * fields remain unchanged in the response frame. 154 */ 155 #define BT_AVRCP_HDR_SET_SUBUNIT_TYPE(hdr, subunit_type) \ 156 (hdr)->byte1 = (((hdr)->byte1) & ~GENMASK(7, 3)) | FIELD_PREP(GENMASK(7, 3), (subunit_type)) 157 158 /** The Packet Type field qualifies each packet as either start (Packet Type=01), continue 159 * (Packet Type=10), or end packet (Packet Type=11). In the case of a non-fragmented message, this 160 * field (Packet Type=00) simply indicates that the message is sent in a single AV/C frame. 161 */ 162 #define BT_AVRCP_AVC_PDU_GET_PACKET_TYPE(pdu) FIELD_GET(GENMASK(1, 0), ((pdu)->pkt_type)) 163 164 /** The Packet Type field qualifies each packet as either start (Packet Type=01), continue 165 * (Packet Type=10), or end packet (Packet Type=11). In the case of a non-fragmented message, this 166 * field (Packet Type=00) simply indicates that the message is sent in a single AV/C frame. 167 */ 168 #define BT_AVRCP_AVC_PDU_SET_PACKET_TYPE(pdu, packet_type) \ 169 (pdu)->pkt_type = FIELD_PREP(GENMASK(1, 0), (packet_type)) 170 171 struct bt_avrcp_frame { 172 struct bt_avrcp_header hdr; 173 uint8_t data[]; 174 } __packed; 175 176 int bt_avrcp_init(void); 177