Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2009-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 #ifndef BT_HCI_LIB_H
     20 #define BT_HCI_LIB_H
     21 
     22 #include <stdint.h>
     23 #include <sys/cdefs.h>
     24 #include <sys/types.h>
     25 
     26 /** Struct types */
     27 
     28 
     29 /** Typedefs and defines */
     30 
     31 /* Generic purpose transac returned upon request complete */
     32 typedef void* TRANSAC;
     33 
     34 /** Bluetooth Power Control States */
     35 typedef enum {
     36     BT_HC_CHIP_PWR_OFF,
     37     BT_HC_CHIP_PWR_ON,
     38 }  bt_hc_chip_power_state_t;
     39 
     40 /** Bluetooth Low Power Mode */
     41 typedef enum {
     42     BT_HC_LPM_DISABLE,
     43     BT_HC_LPM_ENABLE,
     44     BT_HC_LPM_WAKE_ASSERT,
     45     BT_HC_LPM_WAKE_DEASSERT,
     46 } bt_hc_low_power_event_t;
     47 
     48 /** Receive flow control */
     49 typedef enum {
     50     BT_RXFLOW_OFF, /* add transport device fd to select set */
     51     BT_RXFLOW_ON,  /* remove transport device to from select set */
     52 } bt_rx_flow_state_t;
     53 
     54 /** HCI logging control */
     55 typedef enum {
     56     BT_HC_LOGGING_OFF,
     57     BT_HC_LOGGING_ON,
     58 } bt_hc_logging_state_t;
     59 
     60 /** Result of write request */
     61 typedef enum {
     62     BT_HC_TX_SUCCESS,  /* a buffer is fully processed and can be released */
     63     BT_HC_TX_FAIL,     /* transmit fail */
     64     BT_HC_TX_FRAGMENT, /* send split ACL pkt back to stack to reprocess */
     65 } bt_hc_transmit_result_t;
     66 
     67 /** Result of preload initialization */
     68 typedef enum {
     69     BT_HC_PRELOAD_SUCCESS,
     70     BT_HC_PRELOAD_FAIL,
     71 } bt_hc_preload_result_t;
     72 
     73 /** Result of postload initialization */
     74 typedef enum {
     75     BT_HC_POSTLOAD_SUCCESS,
     76     BT_HC_POSTLOAD_FAIL,
     77 } bt_hc_postload_result_t;
     78 
     79 /** Result of low power enable/disable request */
     80 typedef enum {
     81     BT_HC_LPM_DISABLED,
     82     BT_HC_LPM_ENABLED,
     83 } bt_hc_lpm_request_result_t;
     84 
     85 /** Host/Controller Library Return Status */
     86 typedef enum {
     87     BT_HC_STATUS_SUCCESS,
     88     BT_HC_STATUS_FAIL,
     89     BT_HC_STATUS_NOT_READY,
     90     BT_HC_STATUS_NOMEM,
     91     BT_HC_STATUS_BUSY,
     92     BT_HC_STATUS_CORRUPTED_BUFFER
     93 } bt_hc_status_t;
     94 
     95 
     96 /* Section comment */
     97 
     98 /*
     99  * Bluetooth Host/Controller callback structure.
    100  */
    101 
    102 /* called upon bt host wake signal */
    103 typedef void (*hostwake_ind_cb)(bt_hc_low_power_event_t event);
    104 
    105 /* preload initialization callback */
    106 typedef void (*preload_result_cb)(TRANSAC transac, bt_hc_preload_result_t result);
    107 
    108 /* postload initialization callback */
    109 typedef void (*postload_result_cb)(TRANSAC transac, bt_hc_postload_result_t result);
    110 
    111 /* lpm enable/disable callback */
    112 typedef void (*lpm_result_cb)(bt_hc_lpm_request_result_t result);
    113 
    114 /* datapath buffer allocation callback (callout) */
    115 typedef char* (*alloc_mem_cb)(int size);
    116 
    117 /* datapath buffer deallocation callback (callout) */
    118 typedef int (*dealloc_mem_cb)(TRANSAC transac, char *p_buf);
    119 
    120 /* transmit result callback */
    121 typedef int (*tx_result_cb)(TRANSAC transac, char *p_buf, bt_hc_transmit_result_t result);
    122 
    123 /* a previously setup buffer is read and available for processing
    124    buffer is deallocated in stack when processed */
    125 typedef int (*data_ind_cb)(TRANSAC transac, char *p_buf, int len);
    126 
    127 typedef struct {
    128     /** set to sizeof(bt_hc_callbacks_t) */
    129     size_t         size;
    130 
    131     /* notifies caller result of preload request */
    132     preload_result_cb  preload_cb;
    133 
    134     /* notifies caller result of postload request */
    135     postload_result_cb  postload_cb;
    136 
    137     /* notifies caller result of lpm enable/disable */
    138     lpm_result_cb  lpm_cb;
    139 
    140     /* notifies hardware on host wake state */
    141     hostwake_ind_cb       hostwake_ind;
    142 
    143     /* buffer allocation request */
    144     alloc_mem_cb   alloc;
    145 
    146     /* buffer deallocation request */
    147     dealloc_mem_cb dealloc;
    148 
    149     /* notifies stack data is available */
    150     data_ind_cb data_ind;
    151 
    152     /* notifies caller when a buffer is transmitted (or failed) */
    153     tx_result_cb  tx_result;
    154 } bt_hc_callbacks_t;
    155 
    156 /*
    157  * Bluetooth Host/Controller Interface
    158  */
    159 typedef struct {
    160     /** Set to sizeof(bt_hc_interface_t) */
    161     size_t          size;
    162 
    163     /**
    164      * Opens the interface and provides the callback routines
    165      * to the implemenation of this interface.
    166      */
    167     int   (*init)(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr);
    168 
    169     /** Chip power control */
    170     void (*set_power)(bt_hc_chip_power_state_t state);
    171 
    172     /** Set low power mode wake */
    173     int   (*lpm)(bt_hc_low_power_event_t event);
    174 
    175     /** Called prior to stack initialization */
    176     void (*preload)(TRANSAC transac);
    177 
    178     /** Called post stack initialization */
    179     void (*postload)(TRANSAC transac);
    180 
    181     /** Transmit buffer */
    182     int (*transmit_buf)(TRANSAC transac, char *p_buf, int len);
    183 
    184     /** Controls receive flow */
    185     int (*set_rxflow)(bt_rx_flow_state_t state);
    186 
    187     /** Controls HCI logging on/off */
    188     int (*logging)(bt_hc_logging_state_t state, char *p_path);
    189 
    190     /** Closes the interface */
    191     void  (*cleanup)( void );
    192 } bt_hc_interface_t;
    193 
    194 
    195 /*
    196  * External shared lib functions
    197  */
    198 
    199 extern const bt_hc_interface_t* bt_hc_get_interface(void);
    200 
    201 #endif /* BT_HCI_LIB_H */
    202 
    203