• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2001-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 Bluetooth Network
22  *  Encapsilation Protocol (BNEP).
23  *
24  ******************************************************************************/
25 #ifndef BNEP_API_H
26 #define BNEP_API_H
27 
28 #include "l2c_api.h"
29 
30 /*****************************************************************************
31  *  Constants
32  ****************************************************************************/
33 
34 /* Define the minimum offset needed in a GKI buffer for
35  * sending BNEP packets. Note, we are currently not sending
36  * extension headers, but may in the future, so allow
37  * space for them
38 */
39 #define BNEP_MINIMUM_OFFSET (15 + L2CAP_MIN_OFFSET)
40 #define BNEP_INVALID_HANDLE 0xFFFF
41 
42 /*****************************************************************************
43  *  Type Definitions
44  ****************************************************************************/
45 
46 /* Define the result codes from BNEP
47 */
48 enum {
49   BNEP_SUCCESS,               /* Success                           */
50   BNEP_CONN_DISCONNECTED,     /* Connection terminated   */
51   BNEP_NO_RESOURCES,          /* No resources                      */
52   BNEP_MTU_EXCEDED,           /* Attempt to write long data        */
53   BNEP_INVALID_OFFSET,        /* Insufficient offset in GKI buffer */
54   BNEP_CONN_FAILED,           /* Connection failed                 */
55   BNEP_CONN_FAILED_CFG,       /* Connection failed cos of config   */
56   BNEP_CONN_FAILED_SRC_UUID,  /* Connection failed wrong source UUID   */
57   BNEP_CONN_FAILED_DST_UUID,  /* Connection failed wrong destination UUID   */
58   BNEP_CONN_FAILED_UUID_SIZE, /* Connection failed wrong size UUID   */
59   BNEP_Q_SIZE_EXCEEDED,       /* Too many buffers to dest          */
60   BNEP_TOO_MANY_FILTERS,      /* Too many local filters specified  */
61   BNEP_SET_FILTER_FAIL,       /* Set Filter failed  */
62   BNEP_WRONG_HANDLE,          /* Wrong handle for the connection  */
63   BNEP_WRONG_STATE,           /* Connection is in wrong state */
64   BNEP_SECURITY_FAIL,         /* Failed because of security */
65   BNEP_IGNORE_CMD,            /* To ignore the rcvd command */
66   BNEP_TX_FLOW_ON,            /* tx data flow enabled */
67   BNEP_TX_FLOW_OFF            /* tx data flow disabled */
68 
69 };
70 typedef uint8_t tBNEP_RESULT;
71 
72 /***************************
73  *  Callback Functions
74  ***************************/
75 
76 /* Connection state change callback prototype. Parameters are
77  *              Connection handle
78  *              BD Address of remote
79  *              Connection state change result
80  *                  BNEP_SUCCESS indicates connection is success
81  *                  All values are used to indicate the reason for failure
82  *              Flag to indicate if it is just a role change
83 */
84 typedef void(tBNEP_CONN_STATE_CB)(uint16_t handle, const RawAddress& rem_bda,
85                                   tBNEP_RESULT result, bool is_role_change);
86 
87 /* Connection indication callback prototype. Parameters are
88  *              BD Address of remote, remote UUID and local UUID
89  *              and flag to indicate role change and handle to the connection
90  *              When BNEP calls this function profile should
91  *              use BNEP_ConnectResp call to accept or reject the request
92 */
93 typedef void(tBNEP_CONNECT_IND_CB)(uint16_t handle, const RawAddress& bd_addr,
94                                    tBT_UUID* remote_uuid, tBT_UUID* local_uuid,
95                                    bool is_role_change);
96 
97 /* Data buffer received indication callback prototype. Parameters are
98  *              Handle to the connection
99  *              Source BD/Ethernet Address
100  *              Dest BD/Ethernet address
101  *              Protocol
102  *              Pointer to the buffer
103  *              Flag to indicate whether extension headers to be forwarded are
104  *                present
105  */
106 typedef void(tBNEP_DATA_BUF_CB)(uint16_t handle, const RawAddress& src,
107                                 const RawAddress& dst, uint16_t protocol,
108                                 BT_HDR* p_buf, bool fw_ext_present);
109 
110 /* Data received indication callback prototype. Parameters are
111  *              Handle to the connection
112  *              Source BD/Ethernet Address
113  *              Dest BD/Ethernet address
114  *              Protocol
115  *              Pointer to the beginning of the data
116  *              Length of data
117  *              Flag to indicate whether extension headers to be forwarded are
118  *                present
119  */
120 typedef void(tBNEP_DATA_IND_CB)(uint16_t handle, const RawAddress& src,
121                                 const RawAddress& dst, uint16_t protocol,
122                                 uint8_t* p_data, uint16_t len,
123                                 bool fw_ext_present);
124 
125 /* Flow control callback for TX data. Parameters are
126  *              Handle to the connection
127  *              Event  flow status
128 */
129 typedef void(tBNEP_TX_DATA_FLOW_CB)(uint16_t handle, tBNEP_RESULT event);
130 
131 /* Filters received indication callback prototype. Parameters are
132  *              Handle to the connection
133  *              true if the cb is called for indication
134  *              Ignore this if it is indication, otherwise it is the result
135  *                      for the filter set operation performed by the local
136  *                      device
137  *              Number of protocol filters present
138  *              Pointer to the filters start. Filters are present in pairs
139  *                      of start of the range and end of the range.
140  *                      They will be present in big endian order. First
141  *                      two bytes will be starting of the first range and
142  *                      next two bytes will be ending of the range.
143 */
144 typedef void(tBNEP_FILTER_IND_CB)(uint16_t handle, bool indication,
145                                   tBNEP_RESULT result, uint16_t num_filters,
146                                   uint8_t* p_filters);
147 
148 /* Multicast Filters received indication callback prototype. Parameters are
149  *              Handle to the connection
150  *              true if the cb is called for indication
151  *              Ignore this if it is indication, otherwise it is the result
152  *                      for the filter set operation performed by the local
153  *                      device
154  *              Number of multicast filters present
155  *              Pointer to the filters start. Filters are present in pairs
156  *                      of start of the range and end of the range.
157  *                      First six bytes will be starting of the first range and
158  *                      next six bytes will be ending of the range.
159 */
160 typedef void(tBNEP_MFILTER_IND_CB)(uint16_t handle, bool indication,
161                                    tBNEP_RESULT result, uint16_t num_mfilters,
162                                    uint8_t* p_mfilters);
163 
164 /* This is the structure used by profile to register with BNEP */
165 typedef struct {
166   tBNEP_CONNECT_IND_CB* p_conn_ind_cb;  /* To indicate the conn request */
167   tBNEP_CONN_STATE_CB* p_conn_state_cb; /* To indicate conn state change */
168   tBNEP_DATA_IND_CB* p_data_ind_cb;     /* To pass the data received */
169   tBNEP_DATA_BUF_CB* p_data_buf_cb;     /* To pass the data buffer received */
170   tBNEP_TX_DATA_FLOW_CB* p_tx_data_flow_cb; /* data flow callback */
171   tBNEP_FILTER_IND_CB*
172       p_filter_ind_cb; /* To indicate that peer set protocol filters */
173   tBNEP_MFILTER_IND_CB*
174       p_mfilter_ind_cb; /* To indicate that peer set mcast filters */
175 
176 } tBNEP_REGISTER;
177 
178 /* This is the structure used by profile to get the status of BNEP */
179 typedef struct {
180 #define BNEP_STATUS_FAILE 0
181 #define BNEP_STATUS_CONNECTED 1
182   uint8_t con_status;
183 
184   uint16_t l2cap_cid;
185   RawAddress rem_bda;
186   uint16_t rem_mtu_size;
187   uint16_t xmit_q_depth;
188 
189   uint16_t sent_num_filters;
190   uint16_t sent_mcast_filters;
191   uint16_t rcvd_num_filters;
192   uint16_t rcvd_mcast_filters;
193   tBT_UUID src_uuid;
194   tBT_UUID dst_uuid;
195 
196 } tBNEP_STATUS;
197 
198 /*****************************************************************************
199  *  External Function Declarations
200  ****************************************************************************/
201 /*******************************************************************************
202  *
203  * Function         BNEP_Register
204  *
205  * Description      This function is called by the upper layer to register
206  *                  its callbacks with BNEP
207  *
208  * Parameters:      p_reg_info - contains all callback function pointers
209  *
210  *
211  * Returns          BNEP_SUCCESS        if registered successfully
212  *                  BNEP_FAILURE        if connection state callback is missing
213  *
214  ******************************************************************************/
215 extern tBNEP_RESULT BNEP_Register(tBNEP_REGISTER* p_reg_info);
216 
217 /*******************************************************************************
218  *
219  * Function         BNEP_Deregister
220  *
221  * Description      This function is called by the upper layer to de-register
222  *                  its callbacks.
223  *
224  * Parameters:      void
225  *
226  *
227  * Returns          void
228  *
229  ******************************************************************************/
230 extern void BNEP_Deregister(void);
231 
232 /*******************************************************************************
233  *
234  * Function         BNEP_Connect
235  *
236  * Description      This function creates a BNEP connection to a remote
237  *                  device.
238  *
239  * Parameters:      p_rem_addr - BD_ADDR of the peer
240  *                  src_uuid   - source uuid for the connection
241  *                  dst_uuid   - destination uuid for the connection
242  *                  p_handle   - pointer to return the handle for the connection
243  *
244  * Returns          BNEP_SUCCESS                if connection started
245  *                  BNEP_NO_RESOURCES           if no resources
246  *
247  ******************************************************************************/
248 extern tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda,
249                                  tBT_UUID* src_uuid, tBT_UUID* dst_uuid,
250                                  uint16_t* p_handle);
251 
252 /*******************************************************************************
253  *
254  * Function         BNEP_ConnectResp
255  *
256  * Description      This function is called in responce to connection indication
257  *
258  *
259  * Parameters:      handle  - handle given in the connection indication
260  *                  resp    - responce for the connection indication
261  *
262  * Returns          BNEP_SUCCESS                if connection started
263  *                  BNEP_WRONG_HANDLE           if the connection is not found
264  *                  BNEP_WRONG_STATE            if the responce is not expected
265  *
266  ******************************************************************************/
267 extern tBNEP_RESULT BNEP_ConnectResp(uint16_t handle, tBNEP_RESULT resp);
268 
269 /*******************************************************************************
270  *
271  * Function         BNEP_Disconnect
272  *
273  * Description      This function is called to close the specified connection.
274  *
275  * Parameters:      handle   - handle of the connection
276  *
277  * Returns          BNEP_SUCCESS                if connection is disconnected
278  *                  BNEP_WRONG_HANDLE           if no connection is not found
279  *
280  ******************************************************************************/
281 extern tBNEP_RESULT BNEP_Disconnect(uint16_t handle);
282 
283 /*******************************************************************************
284  *
285  * Function         BNEP_WriteBuf
286  *
287  * Description      This function sends data in a GKI buffer on BNEP connection
288  *
289  * Parameters:      handle       - handle of the connection to write
290  *                  p_dest_addr  - BD_ADDR/Ethernet addr of the destination
291  *                  p_buf        - pointer to address of buffer with data
292  *                  protocol     - protocol type of the packet
293  *                  p_src_addr   - (optional) BD_ADDR/ethernet address of the
294  *                                 source (should be NULL if it is the local BD
295  *                                         Addr)
296  *                  fw_ext_present - forwarded extensions present
297  *
298  * Returns:         BNEP_WRONG_HANDLE       - if passed handle is not valid
299  *                  BNEP_MTU_EXCEDED        - If the data length is greater
300  *                                            than MTU
301  *                  BNEP_IGNORE_CMD         - If the packet is filtered out
302  *                  BNEP_Q_SIZE_EXCEEDED    - If the Tx Q is full
303  *                  BNEP_SUCCESS            - If written successfully
304  *
305  ******************************************************************************/
306 extern tBNEP_RESULT BNEP_WriteBuf(uint16_t handle,
307                                   const RawAddress& p_dest_addr, BT_HDR* p_buf,
308                                   uint16_t protocol,
309                                   const RawAddress* p_src_addr,
310                                   bool fw_ext_present);
311 
312 /*******************************************************************************
313  *
314  * Function         BNEP_Write
315  *
316  * Description      This function sends data over a BNEP connection
317  *
318  * Parameters:      handle       - handle of the connection to write
319  *                  p_dest_addr  - BD_ADDR/Ethernet addr of the destination
320  *                  p_data       - pointer to data start
321  *                  protocol     - protocol type of the packet
322  *                  p_src_addr   - (optional) BD_ADDR/ethernet address of the
323  *                                 source (should be NULL if it is the local BD
324  *                                 Addr)
325  *                  fw_ext_present - forwarded extensions present
326  *
327  * Returns:         BNEP_WRONG_HANDLE       - if passed handle is not valid
328  *                  BNEP_MTU_EXCEDED        - If the data length is greater than
329  *                                            the MTU
330  *                  BNEP_IGNORE_CMD         - If the packet is filtered out
331  *                  BNEP_Q_SIZE_EXCEEDED    - If the Tx Q is full
332  *                  BNEP_NO_RESOURCES       - If not able to allocate a buffer
333  *                  BNEP_SUCCESS            - If written successfully
334  *
335  ******************************************************************************/
336 extern tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& p_dest_addr,
337                                uint8_t* p_data, uint16_t len, uint16_t protocol,
338                                const RawAddress* p_src_addr,
339                                bool fw_ext_present);
340 
341 /*******************************************************************************
342  *
343  * Function         BNEP_SetProtocolFilters
344  *
345  * Description      This function sets the protocol filters on peer device
346  *
347  * Parameters:      handle        - Handle for the connection
348  *                  num_filters   - total number of filter ranges
349  *                  p_start_array - Array of beginings of all protocol ranges
350  *                  p_end_array   - Array of ends of all protocol ranges
351  *
352  * Returns          BNEP_WRONG_HANDLE           - if the connection handle is
353  *                                                not valid
354  *                  BNEP_SET_FILTER_FAIL        - if the connection is in the
355  *                                                wrong state
356  *                  BNEP_TOO_MANY_FILTERS       - if too many filters
357  *                  BNEP_SUCCESS                - if request sent successfully
358  *
359  ******************************************************************************/
360 extern tBNEP_RESULT BNEP_SetProtocolFilters(uint16_t handle,
361                                             uint16_t num_filters,
362                                             uint16_t* p_start_array,
363                                             uint16_t* p_end_array);
364 
365 /*******************************************************************************
366  *
367  * Function         BNEP_SetMulticastFilters
368  *
369  * Description      This function sets the filters for multicast addresses for
370  *                  BNEP.
371  *
372  * Parameters:      handle        - Handle for the connection
373  *                  num_filters   - total number of filter ranges
374  *                  p_start_array - Pointer to sequence of beginings of all
375  *                                         multicast address ranges
376  *                  p_end_array   - Pointer to sequence of ends of all
377  *                                         multicast address ranges
378  *
379  * Returns          BNEP_WRONG_HANDLE           - if the connection handle is
380  *                                                not valid
381  *                  BNEP_SET_FILTER_FAIL        - if the connection is in the
382  *                                                wrong state
383  *                  BNEP_TOO_MANY_FILTERS       - if too many filters
384  *                  BNEP_SUCCESS                - if request sent successfully
385  *
386  ******************************************************************************/
387 extern tBNEP_RESULT BNEP_SetMulticastFilters(uint16_t handle,
388                                              uint16_t num_filters,
389                                              uint8_t* p_start_array,
390                                              uint8_t* p_end_array);
391 
392 /*******************************************************************************
393  *
394  * Function         BNEP_SetTraceLevel
395  *
396  * Description      This function sets the trace level for BNEP. If called with
397  *                  a value of 0xFF, it simply reads the current trace level.
398  *
399  * Returns          the new (current) trace level
400  *
401  ******************************************************************************/
402 extern uint8_t BNEP_SetTraceLevel(uint8_t new_level);
403 
404 /*******************************************************************************
405  *
406  * Function         BNEP_Init
407  *
408  * Description      This function initializes the BNEP unit. It should be called
409  *                  before accessing any other APIs to initialize the control
410  *                  block
411  *
412  * Returns          void
413  *
414  ******************************************************************************/
415 extern void BNEP_Init(void);
416 
417 /*******************************************************************************
418  *
419  * Function         BNEP_GetStatus
420  *
421  * Description      This function gets the status information for BNEP
422  *                  connection
423  *
424  * Returns          BNEP_SUCCESS            - if the status is available
425  *                  BNEP_NO_RESOURCES       - if no structure is passed for
426  *                                            output
427  *                  BNEP_WRONG_HANDLE       - if the handle is invalid
428  *                  BNEP_WRONG_STATE        - if not in connected state
429  *
430  ******************************************************************************/
431 extern tBNEP_RESULT BNEP_GetStatus(uint16_t handle, tBNEP_STATUS* p_status);
432 
433 #endif
434