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_COED (7) /* Fixed value according to TA Document 2001012 */
22 
23 typedef enum __packed {
24 	BT_AVRCP_SUBUNIT_ID_ZERO = 0x0,
25 	BT_AVRCP_SUBUNIT_ID_IGNORE = 0x7,
26 } bt_avrcp_subunit_id_t;
27 
28 typedef enum __packed {
29 	BT_AVRCP_SUBUNIT_TYPE_PANEL = 0x9,
30 	BT_AVRCP_SUBUNIT_TYPE_UNIT = 0x1F,
31 } bt_avrcp_subunit_type_t;
32 
33 typedef enum __packed {
34 	BT_AVRCP_OPC_VENDOR_DEPENDENT = 0x0,
35 	BT_AVRCP_OPC_UNIT_INFO = 0x30,
36 	BT_AVRCP_OPC_SUBUNIT_INFO = 0x31,
37 	BT_AVRCP_OPC_PASS_THROUGH = 0x7c,
38 } bt_avrcp_opcode_t;
39 
40 struct bt_avrcp_req {
41 	uint8_t tid;
42 	uint8_t subunit;
43 	uint8_t opcode;
44 };
45 
46 struct bt_avrcp_header {
47 	uint8_t byte0;  /** [7:4]: RFA, [3:0]: Ctype */
48 	uint8_t byte1;  /** [7:3]: Subunit_type, [2:0]: Subunit_ID */
49 	uint8_t opcode; /** Unit Info, Subunit Info, Vendor Dependent, or Pass Through */
50 } __packed;
51 
52 /** The 4-bit command type or the 4-bit response code. */
53 #define BT_AVRCP_HDR_GET_CTYPE_OR_RSP(hdr)        FIELD_GET(GENMASK(3, 0), ((hdr)->byte0))
54 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s  address
55  *  within the target. These fields enable the target to determine  whether the command is
56  *  addressed to the target  unit, or to a specific subunit within the target. The values in these
57  *  fields remain unchanged in the response frame.
58  */
59 #define BT_AVRCP_HDR_GET_SUBUNIT_ID(hdr)   FIELD_GET(GENMASK(2, 0), ((hdr)->byte1))
60 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s  address
61  *  within the target. These fields enable the target to determine  whether the command is
62  *  addressed to the target  unit, or to a specific subunit within the target. The values in these
63  *  fields remain unchanged in the response frame.
64  */
65 #define BT_AVRCP_HDR_GET_SUBUNIT_TYPE(hdr) FIELD_GET(GENMASK(7, 3), ((hdr)->byte1))
66 
67 /** The 4-bit command type or the 4-bit response code. */
68 #define BT_AVRCP_HDR_SET_CTYPE_OR_RSP(hdr, ctype)                                                  \
69 	(hdr)->byte0 = (((hdr)->byte0) & ~GENMASK(3, 0)) | FIELD_PREP(GENMASK(3, 0), (ctype))
70 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s  address
71  *  within the target. These fields enable the target to determine  whether the command is
72  *  addressed to the target  unit, or to a specific subunit within the target. The values in these
73  *  fields remain unchanged in the response frame.
74  */
75 #define BT_AVRCP_HDR_SET_SUBUNIT_ID(hdr, subunit_id)                                               \
76 	(hdr)->byte1 = (((hdr)->byte1) & ~GENMASK(2, 0)) | FIELD_PREP(GENMASK(2, 0), (subunit_id))
77 /** Taken together, the subunit_type and subunit_ID fields define the command recipient’s  address
78  *  within the target. These fields enable the target to determine  whether the command is
79  *  addressed to the target  unit, or to a specific subunit within the target. The values in these
80  *  fields remain unchanged in the response frame.
81  */
82 #define BT_AVRCP_HDR_SET_SUBUNIT_TYPE(hdr, subunit_type)                                           \
83 	(hdr)->byte1 = (((hdr)->byte1) & ~GENMASK(7, 3)) | FIELD_PREP(GENMASK(7, 3), (subunit_type))
84 
85 struct bt_avrcp_frame {
86 	struct bt_avrcp_header hdr;
87 	uint8_t data[0];
88 } __packed;
89 
90 int bt_avrcp_init(void);
91