1 /******************************************************************************
2  *
3  *  Copyright 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  *  This interface file contains the interface to the Audio Video Control
22  *  Transport Protocol (AVCTP).
23  *
24  ******************************************************************************/
25 #ifndef AVCT_API_H
26 #define AVCT_API_H
27 
28 #include <cstdint>
29 
30 #include "internal_include/bt_target.h"
31 #include "stack/include/bt_hdr.h"
32 #include "types/raw_address.h"
33 
34 /*****************************************************************************
35  *  Constants
36  ****************************************************************************/
37 
38 /* API function return value result codes. */
39 #define AVCT_SUCCESS 0      /* Function successful */
40 #define AVCT_NO_RESOURCES 1 /* Not enough resources */
41 #define AVCT_BAD_HANDLE 2   /* Bad handle */
42 #define AVCT_PID_IN_USE 3   /* PID already in use */
43 #define AVCT_NOT_OPEN 4     /* Connection not open */
44 
45 /* PSM for AVCT. */
46 #define AVCT_PSM 0x0017
47 #define AVCT_BR_PSM 0x001B
48 
49 /* Protocol revision numbers */
50 #define AVCT_REV_1_0 0x0100
51 #define AVCT_REV_1_2 0x0102
52 #define AVCT_REV_1_3 0x0103
53 #define AVCT_REV_1_4 0x0104
54 
55 /* the layer_specific settings */
56 #define AVCT_DATA_CTRL 0x0001    /* for the control channel */
57 #define AVCT_DATA_BROWSE 0x0002  /* for the browsing channel */
58 #define AVCT_DATA_PARTIAL 0x0100 /* Only have room for a partial message */
59 
60 /* Per the AVRC spec, minimum MTU for the control channel */
61 #define AVCT_MIN_CONTROL_MTU 48
62 /* Per the AVRC spec, minimum MTU for the browsing channel */
63 #define AVCT_MIN_BROWSE_MTU 335
64 
65 /* Message offset.  The number of bytes needed by the protocol stack for the
66  * protocol headers of an AVCTP message packet.
67 */
68 #define AVCT_MSG_OFFSET 15
69 #define AVCT_BROWSE_OFFSET 17 /* the default offset for browsing channel */
70 
71 /* Connection role. */
72 #define AVCT_INT 0 /* Initiator connection */
73 #define AVCT_ACP 1 /* Acceptor connection */
74 
75 /* Control role. */
76 #define AVCT_TARGET 1  /* target  */
77 #define AVCT_CONTROL 2 /* controller  */
78 #define AVCT_PASSIVE 4 /* If conflict, allow the other side to succeed  */
79 
80 /* Command/Response indicator. */
81 #define AVCT_CMD 0 /* Command message */
82 #define AVCT_RSP 2 /* Response message */
83 #define AVCT_REJ 3 /* Message rejected */
84 
85 /* Control callback events. */
86 #define AVCT_CONNECT_CFM_EVT 0        /* Connection confirm */
87 #define AVCT_CONNECT_IND_EVT 1        /* Connection indication */
88 #define AVCT_DISCONNECT_CFM_EVT 2     /* Disconnect confirm */
89 #define AVCT_DISCONNECT_IND_EVT 3     /* Disconnect indication */
90 #define AVCT_CONG_IND_EVT 4           /* Congestion indication */
91 #define AVCT_UNCONG_IND_EVT 5         /* Uncongestion indication */
92 #define AVCT_BROWSE_CONN_CFM_EVT 6    /* Browse Connection confirm */
93 #define AVCT_BROWSE_CONN_IND_EVT 7    /* Browse Connection indication */
94 #define AVCT_BROWSE_DISCONN_CFM_EVT 8 /* Browse Disconnect confirm */
95 #define AVCT_BROWSE_DISCONN_IND_EVT 9 /* Browse Disconnect indication */
96 #define AVCT_BROWSE_CONG_IND_EVT 10   /* Congestion indication */
97 #define AVCT_BROWSE_UNCONG_IND_EVT 11 /* Uncongestion indication */
98 
99 /* General purpose failure result code for callback events. */
100 #define AVCT_RESULT_FAIL 5
101 
102 /*****************************************************************************
103  *  Type Definitions
104  ****************************************************************************/
105 
106 /* Control callback function. */
107 typedef void(tAVCT_CTRL_CBACK)(uint8_t handle, uint8_t event, uint16_t result,
108                                const RawAddress* peer_addr);
109 
110 /* Message callback function */
111 /* p_pkt->layer_specific is AVCT_DATA_CTRL or AVCT_DATA_BROWSE */
112 typedef void(tAVCT_MSG_CBACK)(uint8_t handle, uint8_t label, uint8_t cr,
113                               BT_HDR* p_pkt);
114 
115 /* Structure used by AVCT_CreateConn. */
116 typedef struct {
117   tAVCT_CTRL_CBACK* p_ctrl_cback; /* Control callback */
118   tAVCT_MSG_CBACK* p_msg_cback;   /* Message callback */
119   uint16_t pid;                   /* Profile ID */
120   uint8_t role;                   /* Initiator/acceptor role */
121   uint8_t control;                /* Control role (Control/Target) */
122 } tAVCT_CC;
123 
124 /*****************************************************************************
125  *  External Function Declarations
126  ****************************************************************************/
127 
128 /*******************************************************************************
129  *
130  * Function         AVCT_Register
131  *
132  * Description      This is the system level registration function for the
133  *                  AVCTP protocol.  This function initializes AVCTP and
134  *                  prepares the protocol stack for its use.  This function
135  *                  must be called once by the system or platform using AVCTP
136  *                  before the other functions of the API an be used.
137  *
138  *
139  * Returns          void
140  *
141  ******************************************************************************/
142 void AVCT_Register();
143 
144 /*******************************************************************************
145  *
146  * Function         AVCT_Deregister
147  *
148  * Description      This function is called to deregister use AVCTP protocol.
149  *                  It is called when AVCTP is no longer being used by any
150  *                  application in the system.  Before this function can be
151  *                  called, all connections must be removed with
152  *                  AVCT_RemoveConn().
153  *
154  *
155  * Returns          void
156  *
157  ******************************************************************************/
158 void AVCT_Deregister(void);
159 
160 /*******************************************************************************
161  *
162  * Function         AVCT_CreateConn
163  *
164  * Description      Create an AVCTP connection.  There are two types of
165  *                  connections, initiator and acceptor, as determined by
166  *                  the p_cc->role parameter.  When this function is called to
167  *                  create an initiator connection, an AVCTP connection to
168  *                  the peer device is initiated if one does not already exist.
169  *                  If an acceptor connection is created, the connection waits
170  *                  passively for an incoming AVCTP connection from a peer
171  *                  device.
172  *
173  *
174  * Returns          AVCT_SUCCESS if successful, otherwise error.
175  *
176  ******************************************************************************/
177 uint16_t AVCT_CreateConn(uint8_t* p_handle, tAVCT_CC* p_cc,
178                          const RawAddress& peer_addr);
179 
180 /*******************************************************************************
181  *
182  * Function         AVCT_RemoveConn
183  *
184  * Description      Remove an AVCTP connection.  This function is called when
185  *                  the application is no longer using a connection.  If this
186  *                  is the last connection to a peer the L2CAP channel for AVCTP
187  *                  will be closed.
188  *
189  *
190  * Returns          AVCT_SUCCESS if successful, otherwise error.
191  *
192  ******************************************************************************/
193 uint16_t AVCT_RemoveConn(uint8_t handle);
194 
195 /*******************************************************************************
196  *
197  * Function         AVCT_CreateBrowse
198  *
199  * Description      Create an AVCTP connection.  There are two types of
200  *                  connections, initiator and acceptor, as determined by
201  *                  the p_cc->role parameter.  When this function is called to
202  *                  create an initiator connection, an AVCTP connection to
203  *                  the peer device is initiated if one does not already exist.
204  *                  If an acceptor connection is created, the connection waits
205  *                  passively for an incoming AVCTP connection from a peer
206  *                  device.
207  *
208  *
209  * Returns          AVCT_SUCCESS if successful, otherwise error.
210  *
211  ******************************************************************************/
212 uint16_t AVCT_CreateBrowse(uint8_t handle, uint8_t role);
213 
214 /*******************************************************************************
215  *
216  * Function         AVCT_RemoveBrowse
217  *
218  * Description      Remove an AVCTP connection.  This function is called when
219  *                  the application is no longer using a connection.  If this
220  *                  is the last connection to a peer the L2CAP channel for AVCTP
221  *                  will be closed.
222  *
223  *
224  * Returns          AVCT_SUCCESS if successful, otherwise error.
225  *
226  ******************************************************************************/
227 uint16_t AVCT_RemoveBrowse(uint8_t handle);
228 
229 /*******************************************************************************
230  *
231  * Function         AVCT_GetBrowseMtu
232  *
233  * Description      Get the peer_mtu for the AVCTP Browse channel of the given
234  *                  connection.
235  *
236  * Returns          the peer browsing channel MTU.
237  *
238  ******************************************************************************/
239 uint16_t AVCT_GetBrowseMtu(uint8_t handle);
240 
241 /*******************************************************************************
242  *
243  * Function         AVCT_GetPeerMtu
244  *
245  * Description      Get the peer_mtu for the AVCTP channel of the given
246  *                  connection.
247  *
248  * Returns          the peer MTU size.
249  *
250  ******************************************************************************/
251 uint16_t AVCT_GetPeerMtu(uint8_t handle);
252 
253 /*******************************************************************************
254  *
255  * Function         AVCT_MsgReq
256  *
257  * Description      Send an AVCTP message to a peer device.  In calling
258  *                  AVCT_MsgReq(), the application should keep track of the
259  *                  congestion state of AVCTP as communicated with events
260  *                  AVCT_CONG_IND_EVT and AVCT_UNCONG_IND_EVT.   If the
261  *                  application calls AVCT_MsgReq() when AVCTP is congested
262  *                  the message may be discarded.  The application may make its
263  *                  first call to AVCT_MsgReq() after it receives an
264  *                  AVCT_CONNECT_CFM_EVT or AVCT_CONNECT_IND_EVT on control
265  *                  channel or
266  *                  AVCT_BROWSE_CONN_CFM_EVT or AVCT_BROWSE_CONN_IND_EVT on
267  *                  browsing channel.
268  *
269  *                  p_msg->layer_specific must be set to
270  *                  AVCT_DATA_CTRL for control channel traffic;
271  *                  AVCT_DATA_BROWSE for for browse channel traffic.
272  *
273  * Returns          AVCT_SUCCESS if successful, otherwise error.
274  *
275  ******************************************************************************/
276 uint16_t AVCT_MsgReq(uint8_t handle, uint8_t label, uint8_t cr, BT_HDR* p_msg);
277 
278 #endif /* AVCT_API_H */
279