• 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, BD_ADDR 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, BD_ADDR 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, uint8_t* src, uint8_t* dst,
107                                 uint16_t protocol, BT_HDR* p_buf,
108                                 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, uint8_t* src, uint8_t* dst,
121                                 uint16_t protocol, uint8_t* p_data,
122                                 uint16_t len, bool fw_ext_present);
123 
124 /* Flow control callback for TX data. Parameters are
125  *              Handle to the connection
126  *              Event  flow status
127 */
128 typedef void(tBNEP_TX_DATA_FLOW_CB)(uint16_t handle, tBNEP_RESULT event);
129 
130 /* Filters received indication callback prototype. Parameters are
131  *              Handle to the connection
132  *              true if the cb is called for indication
133  *              Ignore this if it is indication, otherwise it is the result
134  *                      for the filter set operation performed by the local
135  *                      device
136  *              Number of protocol filters present
137  *              Pointer to the filters start. Filters are present in pairs
138  *                      of start of the range and end of the range.
139  *                      They will be present in big endian order. First
140  *                      two bytes will be starting of the first range and
141  *                      next two bytes will be ending of the range.
142 */
143 typedef void(tBNEP_FILTER_IND_CB)(uint16_t handle, bool indication,
144                                   tBNEP_RESULT result, uint16_t num_filters,
145                                   uint8_t* p_filters);
146 
147 /* Multicast Filters received indication callback prototype. Parameters are
148  *              Handle to the connection
149  *              true if the cb is called for indication
150  *              Ignore this if it is indication, otherwise it is the result
151  *                      for the filter set operation performed by the local
152  *                      device
153  *              Number of multicast filters present
154  *              Pointer to the filters start. Filters are present in pairs
155  *                      of start of the range and end of the range.
156  *                      First six bytes will be starting of the first range and
157  *                      next six bytes will be ending of the range.
158 */
159 typedef void(tBNEP_MFILTER_IND_CB)(uint16_t handle, bool indication,
160                                    tBNEP_RESULT result, uint16_t num_mfilters,
161                                    uint8_t* p_mfilters);
162 
163 /* This is the structure used by profile to register with BNEP */
164 typedef struct {
165   tBNEP_CONNECT_IND_CB* p_conn_ind_cb;  /* To indicate the conn request */
166   tBNEP_CONN_STATE_CB* p_conn_state_cb; /* To indicate conn state change */
167   tBNEP_DATA_IND_CB* p_data_ind_cb;     /* To pass the data received */
168   tBNEP_DATA_BUF_CB* p_data_buf_cb;     /* To pass the data buffer received */
169   tBNEP_TX_DATA_FLOW_CB* p_tx_data_flow_cb; /* data flow callback */
170   tBNEP_FILTER_IND_CB*
171       p_filter_ind_cb; /* To indicate that peer set protocol filters */
172   tBNEP_MFILTER_IND_CB*
173       p_mfilter_ind_cb; /* To indicate that peer set mcast filters */
174 
175 } tBNEP_REGISTER;
176 
177 /* This is the structure used by profile to get the status of BNEP */
178 typedef struct {
179 #define BNEP_STATUS_FAILE 0
180 #define BNEP_STATUS_CONNECTED 1
181   uint8_t con_status;
182 
183   uint16_t l2cap_cid;
184   BD_ADDR rem_bda;
185   uint16_t rem_mtu_size;
186   uint16_t xmit_q_depth;
187 
188   uint16_t sent_num_filters;
189   uint16_t sent_mcast_filters;
190   uint16_t rcvd_num_filters;
191   uint16_t rcvd_mcast_filters;
192   tBT_UUID src_uuid;
193   tBT_UUID dst_uuid;
194 
195 } tBNEP_STATUS;
196 
197 /*****************************************************************************
198  *  External Function Declarations
199  ****************************************************************************/
200 /*******************************************************************************
201  *
202  * Function         BNEP_Register
203  *
204  * Description      This function is called by the upper layer to register
205  *                  its callbacks with BNEP
206  *
207  * Parameters:      p_reg_info - contains all callback function pointers
208  *
209  *
210  * Returns          BNEP_SUCCESS        if registered successfully
211  *                  BNEP_FAILURE        if connection state callback is missing
212  *
213  ******************************************************************************/
214 extern tBNEP_RESULT BNEP_Register(tBNEP_REGISTER* p_reg_info);
215 
216 /*******************************************************************************
217  *
218  * Function         BNEP_Deregister
219  *
220  * Description      This function is called by the upper layer to de-register
221  *                  its callbacks.
222  *
223  * Parameters:      void
224  *
225  *
226  * Returns          void
227  *
228  ******************************************************************************/
229 extern void BNEP_Deregister(void);
230 
231 /*******************************************************************************
232  *
233  * Function         BNEP_Connect
234  *
235  * Description      This function creates a BNEP connection to a remote
236  *                  device.
237  *
238  * Parameters:      p_rem_addr - BD_ADDR of the peer
239  *                  src_uuid   - source uuid for the connection
240  *                  dst_uuid   - destination uuid for the connection
241  *                  p_handle   - pointer to return the handle for the connection
242  *
243  * Returns          BNEP_SUCCESS                if connection started
244  *                  BNEP_NO_RESOURCES           if no resources
245  *
246  ******************************************************************************/
247 extern tBNEP_RESULT BNEP_Connect(BD_ADDR p_rem_bda, tBT_UUID* src_uuid,
248                                  tBT_UUID* dst_uuid, uint16_t* p_handle);
249 
250 /*******************************************************************************
251  *
252  * Function         BNEP_ConnectResp
253  *
254  * Description      This function is called in responce to connection indication
255  *
256  *
257  * Parameters:      handle  - handle given in the connection indication
258  *                  resp    - responce for the connection indication
259  *
260  * Returns          BNEP_SUCCESS                if connection started
261  *                  BNEP_WRONG_HANDLE           if the connection is not found
262  *                  BNEP_WRONG_STATE            if the responce is not expected
263  *
264  ******************************************************************************/
265 extern tBNEP_RESULT BNEP_ConnectResp(uint16_t handle, tBNEP_RESULT resp);
266 
267 /*******************************************************************************
268  *
269  * Function         BNEP_Disconnect
270  *
271  * Description      This function is called to close the specified connection.
272  *
273  * Parameters:      handle   - handle of the connection
274  *
275  * Returns          BNEP_SUCCESS                if connection is disconnected
276  *                  BNEP_WRONG_HANDLE           if no connection is not found
277  *
278  ******************************************************************************/
279 extern tBNEP_RESULT BNEP_Disconnect(uint16_t handle);
280 
281 /*******************************************************************************
282  *
283  * Function         BNEP_WriteBuf
284  *
285  * Description      This function sends data in a GKI buffer on BNEP connection
286  *
287  * Parameters:      handle       - handle of the connection to write
288  *                  p_dest_addr  - BD_ADDR/Ethernet addr of the destination
289  *                  p_buf        - pointer to address of buffer with data
290  *                  protocol     - protocol type of the packet
291  *                  p_src_addr   - (optional) BD_ADDR/ethernet address of the
292  *                                 source (should be NULL if it is the local BD
293  *                                         Addr)
294  *                  fw_ext_present - forwarded extensions present
295  *
296  * Returns:         BNEP_WRONG_HANDLE       - if passed handle is not valid
297  *                  BNEP_MTU_EXCEDED        - If the data length is greater
298  *                                            than MTU
299  *                  BNEP_IGNORE_CMD         - If the packet is filtered out
300  *                  BNEP_Q_SIZE_EXCEEDED    - If the Tx Q is full
301  *                  BNEP_SUCCESS            - If written successfully
302  *
303  ******************************************************************************/
304 extern tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, uint8_t* p_dest_addr,
305                                   BT_HDR* p_buf, uint16_t protocol,
306                                   uint8_t* p_src_addr, bool fw_ext_present);
307 
308 /*******************************************************************************
309  *
310  * Function         BNEP_Write
311  *
312  * Description      This function sends data over a BNEP connection
313  *
314  * Parameters:      handle       - handle of the connection to write
315  *                  p_dest_addr  - BD_ADDR/Ethernet addr of the destination
316  *                  p_data       - pointer to data start
317  *                  protocol     - protocol type of the packet
318  *                  p_src_addr   - (optional) BD_ADDR/ethernet address of the
319  *                                 source (should be NULL if it is the local BD
320  *                                 Addr)
321  *                  fw_ext_present - forwarded extensions present
322  *
323  * Returns:         BNEP_WRONG_HANDLE       - if passed handle is not valid
324  *                  BNEP_MTU_EXCEDED        - If the data length is greater than
325  *                                            the MTU
326  *                  BNEP_IGNORE_CMD         - If the packet is filtered out
327  *                  BNEP_Q_SIZE_EXCEEDED    - If the Tx Q is full
328  *                  BNEP_NO_RESOURCES       - If not able to allocate a buffer
329  *                  BNEP_SUCCESS            - If written successfully
330  *
331  ******************************************************************************/
332 extern tBNEP_RESULT BNEP_Write(uint16_t handle, uint8_t* p_dest_addr,
333                                uint8_t* p_data, uint16_t len, uint16_t protocol,
334                                uint8_t* p_src_addr, bool fw_ext_present);
335 
336 /*******************************************************************************
337  *
338  * Function         BNEP_SetProtocolFilters
339  *
340  * Description      This function sets the protocol filters on peer device
341  *
342  * Parameters:      handle        - Handle for the connection
343  *                  num_filters   - total number of filter ranges
344  *                  p_start_array - Array of beginings of all protocol ranges
345  *                  p_end_array   - Array of ends of all protocol ranges
346  *
347  * Returns          BNEP_WRONG_HANDLE           - if the connection handle is
348  *                                                not valid
349  *                  BNEP_SET_FILTER_FAIL        - if the connection is in the
350  *                                                wrong state
351  *                  BNEP_TOO_MANY_FILTERS       - if too many filters
352  *                  BNEP_SUCCESS                - if request sent successfully
353  *
354  ******************************************************************************/
355 extern tBNEP_RESULT BNEP_SetProtocolFilters(uint16_t handle,
356                                             uint16_t num_filters,
357                                             uint16_t* p_start_array,
358                                             uint16_t* p_end_array);
359 
360 /*******************************************************************************
361  *
362  * Function         BNEP_SetMulticastFilters
363  *
364  * Description      This function sets the filters for multicast addresses for
365  *                  BNEP.
366  *
367  * Parameters:      handle        - Handle for the connection
368  *                  num_filters   - total number of filter ranges
369  *                  p_start_array - Pointer to sequence of beginings of all
370  *                                         multicast address ranges
371  *                  p_end_array   - Pointer to sequence of ends of all
372  *                                         multicast address ranges
373  *
374  * Returns          BNEP_WRONG_HANDLE           - if the connection handle is
375  *                                                not valid
376  *                  BNEP_SET_FILTER_FAIL        - if the connection is in the
377  *                                                wrong state
378  *                  BNEP_TOO_MANY_FILTERS       - if too many filters
379  *                  BNEP_SUCCESS                - if request sent successfully
380  *
381  ******************************************************************************/
382 extern tBNEP_RESULT BNEP_SetMulticastFilters(uint16_t handle,
383                                              uint16_t num_filters,
384                                              uint8_t* p_start_array,
385                                              uint8_t* p_end_array);
386 
387 /*******************************************************************************
388  *
389  * Function         BNEP_SetTraceLevel
390  *
391  * Description      This function sets the trace level for BNEP. If called with
392  *                  a value of 0xFF, it simply reads the current trace level.
393  *
394  * Returns          the new (current) trace level
395  *
396  ******************************************************************************/
397 extern uint8_t BNEP_SetTraceLevel(uint8_t new_level);
398 
399 /*******************************************************************************
400  *
401  * Function         BNEP_Init
402  *
403  * Description      This function initializes the BNEP unit. It should be called
404  *                  before accessing any other APIs to initialize the control
405  *                  block
406  *
407  * Returns          void
408  *
409  ******************************************************************************/
410 extern void BNEP_Init(void);
411 
412 /*******************************************************************************
413  *
414  * Function         BNEP_GetStatus
415  *
416  * Description      This function gets the status information for BNEP
417  *                  connection
418  *
419  * Returns          BNEP_SUCCESS            - if the status is available
420  *                  BNEP_NO_RESOURCES       - if no structure is passed for
421  *                                            output
422  *                  BNEP_WRONG_HANDLE       - if the handle is invalid
423  *                  BNEP_WRONG_STATE        - if not in connected state
424  *
425  ******************************************************************************/
426 extern tBNEP_RESULT BNEP_GetStatus(uint16_t handle, tBNEP_STATUS* p_status);
427 
428 #endif
429