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