1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  VRCP internal header file.
22  *
23  ******************************************************************************/
24 
25 
26 #ifndef AVRC_INT_H
27 #define AVRC_INT_H
28 
29 #include "avct_defs.h"
30 #include "avrc_api.h"
31 
32 /*      DEBUG FLAGS
33  *
34  * #define META_DEBUG_ENABLED
35  */
36 /*****************************************************************************
37 **  Constants
38 *****************************************************************************/
39 
40 /* Number of attributes in AVRC SDP record. */
41 #define AVRC_NUM_ATTR            6
42 
43 /* Number of protocol elements in protocol element list. */
44 #define AVRC_NUM_PROTO_ELEMS     2
45 
46 #ifndef AVRC_MIN_CMD_LEN
47 #define AVRC_MIN_CMD_LEN    20
48 #endif
49 
50 #define AVRC_UNIT_OPRND_BYTES   5
51 #define AVRC_SUB_OPRND_BYTES    4
52 #define AVRC_SUBRSP_OPRND_BYTES 3
53 #define AVRC_SUB_PAGE_MASK      7
54 #define AVRC_SUB_PAGE_SHIFT     4
55 #define AVRC_SUB_EXT_CODE       7
56 #define AVRC_PASS_OP_ID_MASK    0x7F
57 #define AVRC_PASS_STATE_MASK    0x80
58 #define AVRC_CMD_OPRND_PAD      0xFF
59 
60 #define AVRC_CTYPE_MASK         0x0F
61 #define AVRC_SUBTYPE_MASK       0xF8
62 #define AVRC_SUBTYPE_SHIFT      3
63 #define AVRC_SUBID_MASK         0x07
64 #define AVRC_SUBID_IGNORE       0x07
65 
66 #define AVRC_SINGLE_PARAM_SIZE      1
67 #define AVRC_METADATA_PKT_TYPE_MASK 0x03
68 #define AVRC_PASS_THOUGH_MSG_MASK   0x80           /* MSB of msg_type indicates the PAS THROUGH msg */
69 #define AVRC_VENDOR_UNIQUE_MASK     0x70           /* vendor unique id */
70 
71 
72 /* Company ID is 24-bit integer We can not use the macros in bt_types.h */
73 #define AVRC_CO_ID_TO_BE_STREAM(p, u32) {*(p)++ = (UINT8)((u32) >> 16); *(p)++ = (UINT8)((u32) >> 8); *(p)++ = (UINT8)(u32); }
74 #define AVRC_BE_STREAM_TO_CO_ID(u32, p) {u32 = (((UINT32)(*((p) + 2))) + (((UINT32)(*((p) + 1))) << 8) + (((UINT32)(*(p))) << 16)); (p) += 3;}
75 
76 #define AVRC_AVC_HDR_SIZE           3   /* ctype, subunit*, opcode */
77 
78 #define AVRC_MIN_META_HDR_SIZE      4   /* pdu id(1), packet type(1), param len(2) */
79 #define AVRC_MIN_BROWSE_HDR_SIZE    3   /* pdu id(1), param len(2) */
80 
81 #define AVRC_VENDOR_HDR_SIZE        6   /* ctype, subunit*, opcode, CO_ID */
82 #define AVRC_MSG_VENDOR_OFFSET      23
83 #define AVRC_MIN_VENDOR_SIZE        (AVRC_MSG_VENDOR_OFFSET + BT_HDR_SIZE + AVRC_MIN_META_HDR_SIZE)
84 
85 #define AVRC_PASS_THRU_SIZE         8
86 #define AVRC_MSG_PASS_THRU_OFFSET   25
87 #define AVRC_MIN_PASS_THRU_SIZE     (AVRC_MSG_PASS_THRU_OFFSET + BT_HDR_SIZE + 4)
88 
89 #define AVRC_MIN_BROWSE_SIZE        (AVCT_BROWSE_OFFSET + BT_HDR_SIZE + AVRC_MIN_BROWSE_HDR_SIZE)
90 
91 #define AVRC_CTRL_PKT_LEN(pf, pk)   {pf = (UINT8 *)((pk) + 1) + (pk)->offset + 2;}
92 
93 #define AVRC_MAX_CTRL_DATA_LEN      (AVRC_PACKET_LEN)
94 
95 /*****************************************************************************
96 **  Type definitions
97 *****************************************************************************/
98 
99 #if (AVRC_METADATA_INCLUDED == TRUE)
100 /* type for Metadata fragmentation control block */
101 typedef struct
102 {
103     BT_HDR              *p_fmsg;        /* the fragmented message */
104     UINT8               frag_pdu;       /* the PDU ID for fragmentation */
105     BOOLEAN             frag_enabled;   /* fragmentation flag */
106 } tAVRC_FRAG_CB;
107 
108 /* type for Metadata re-assembly control block */
109 typedef struct
110 {
111     BT_HDR              *p_rmsg;        /* the received message */
112     UINT16              rasm_offset;    /* re-assembly flag, the offset of the start fragment */
113     UINT8               rasm_pdu;       /* the PDU ID for re-assembly */
114 } tAVRC_RASM_CB;
115 #endif
116 
117 typedef struct
118 {
119     tAVRC_CONN_CB       ccb[AVCT_NUM_CONN];
120 #if (AVRC_METADATA_INCLUDED == TRUE)
121     tAVRC_FRAG_CB       fcb[AVCT_NUM_CONN];
122     tAVRC_RASM_CB       rcb[AVCT_NUM_CONN];
123 #endif
124     tAVRC_FIND_CBACK    *p_cback;       /* pointer to application callback */
125     tSDP_DISCOVERY_DB   *p_db;          /* pointer to discovery database */
126     UINT16              service_uuid;   /* service UUID to search */
127     UINT8               trace_level;
128 } tAVRC_CB;
129 
130 
131 
132 #ifdef __cplusplus
133 extern "C"
134 {
135 #endif
136 
137 /******************************************************************************
138 ** Main Control Block
139 *******************************************************************************/
140 #if AVRC_DYNAMIC_MEMORY == FALSE
141 extern tAVRC_CB  avrc_cb;
142 #else
143 extern tAVRC_CB *avrc_cb_ptr;
144 #define avrc_cb (*avrc_cb_ptr)
145 #endif
146 
147 extern BOOLEAN avrc_is_valid_pdu_id(UINT8 pdu_id);
148 extern BOOLEAN avrc_is_valid_player_attrib_value(UINT8 attrib, UINT8 value);
149 extern BT_HDR * avrc_alloc_ctrl_pkt (UINT8 pdu);
150 extern tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS *p_msg, UINT16 *p_vendor_unique_id);
151 extern UINT8 avrc_opcode_from_pdu(UINT8 pdu);
152 extern BOOLEAN avrc_is_valid_opcode(UINT8 opcode);
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #endif /* AVRC_INT_H */
159