diff options
Diffstat (limited to 'hci/include')
-rw-r--r-- | hci/include/bt_hci_bdroid.h | 156 | ||||
-rw-r--r-- | hci/include/bt_hci_lib.h | 202 | ||||
-rw-r--r-- | hci/include/bt_vendor_lib.h | 323 | ||||
-rw-r--r-- | hci/include/hci.h | 86 | ||||
-rw-r--r-- | hci/include/userial.h | 141 | ||||
-rw-r--r-- | hci/include/utils.h | 194 |
6 files changed, 1102 insertions, 0 deletions
diff --git a/hci/include/bt_hci_bdroid.h b/hci/include/bt_hci_bdroid.h new file mode 100644 index 0000000..5681e85 --- /dev/null +++ b/hci/include/bt_hci_bdroid.h @@ -0,0 +1,156 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/****************************************************************************** + * + * Filename: bt_hci_bdroid.h + * + * Description: A wrapper header file of bt_hci_lib.h + * + * Contains definitions specific for interfacing with Bluedroid + * Bluetooth stack + * + ******************************************************************************/ + +#ifndef BT_HCI_BDROID_H +#define BT_HCI_BDROID_H + +#include "bt_hci_lib.h" + +/****************************************************************************** +** Constants & Macros +******************************************************************************/ + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE (!FALSE) +#endif + +#ifndef BTHC_LINUX_BASE_POLICY +#define BTHC_LINUX_BASE_POLICY SCHED_NORMAL +#endif + +#if (BTHC_LINUX_BASE_POLICY != SCHED_NORMAL) +#ifndef BTHC_LINUX_BASE_PRIORITY +#define BTHC_LINUX_BASE_PRIORITY 30 +#endif + +#ifndef BTHC_USERIAL_READ_THREAD_PRIORITY +#define BTHC_USERIAL_READ_THREAD_PRIORITY (BTHC_LINUX_BASE_PRIORITY) +#endif + +#ifndef BTHC_MAIN_THREAD_PRIORITY +#define BTHC_MAIN_THREAD_PRIORITY (BTHC_LINUX_BASE_PRIORITY-1) +#endif +#endif // (BTHC_LINUX_BASE_POLICY != SCHED_NORMAL) + +#ifndef BTHC_USERIAL_READ_MEM_SIZE +#define BTHC_USERIAL_READ_MEM_SIZE (1024) +#endif + +#ifndef BTSNOOPDISP_INCLUDED +#define BTSNOOPDISP_INCLUDED TRUE +#endif + +/* Disable external parser for production */ +#ifndef BTSNOOP_EXT_PARSER_INCLUDED +#define BTSNOOP_EXT_PARSER_INCLUDED FALSE +#endif + +/* Host/Controller lib internal event ID */ +#define HC_EVENT_PRELOAD 0x0001 +#define HC_EVENT_POSTLOAD 0x0002 +#define HC_EVENT_RX 0x0004 +#define HC_EVENT_TX 0x0008 +#define HC_EVENT_LPM_ENABLE 0x0010 +#define HC_EVENT_LPM_DISABLE 0x0020 +#define HC_EVENT_LPM_WAKE_DEVICE 0x0040 +#define HC_EVENT_LPM_ALLOW_SLEEP 0x0080 +#define HC_EVENT_LPM_IDLE_TIMEOUT 0x0100 +#define HC_EVENT_EXIT 0x0200 + +/* Message event mask across Host/Controller lib and stack */ +#define MSG_EVT_MASK 0xFF00 /* eq. BT_EVT_MASK */ +#define MSG_SUB_EVT_MASK 0x00FF /* eq. BT_SUB_EVT_MASK */ + +/* Message event ID passed from Host/Controller lib to stack */ +#define MSG_HC_TO_STACK_HCI_ERR 0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */ +#define MSG_HC_TO_STACK_HCI_ACL 0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */ +#define MSG_HC_TO_STACK_HCI_SCO 0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */ +#define MSG_HC_TO_STACK_HCI_EVT 0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */ +#define MSG_HC_TO_STACK_L2C_SEG_XMIT 0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */ + +/* Message event ID passed from stack to vendor lib */ +#define MSG_STACK_TO_HC_HCI_ACL 0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */ +#define MSG_STACK_TO_HC_HCI_SCO 0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */ +#define MSG_STACK_TO_HC_HCI_CMD 0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */ + +/* Local Bluetooth Controller ID for BR/EDR */ +#define LOCAL_BR_EDR_CONTROLLER_ID 0 + +/****************************************************************************** +** Type definitions and return values +******************************************************************************/ + +typedef struct +{ + uint16_t event; + uint16_t len; + uint16_t offset; + uint16_t layer_specific; +} HC_BT_HDR; + +#define BT_HC_HDR_SIZE (sizeof(HC_BT_HDR)) + + +typedef struct _hc_buffer_hdr +{ + struct _hc_buffer_hdr *p_next; /* next buffer in the queue */ + uint8_t reserved1; + uint8_t reserved2; + uint8_t reserved3; + uint8_t reserved4; +} HC_BUFFER_HDR_T; + +#define BT_HC_BUFFER_HDR_SIZE (sizeof(HC_BUFFER_HDR_T)) + +/****************************************************************************** +** Extern variables and functions +******************************************************************************/ + +extern bt_hc_callbacks_t *bt_hc_cbacks; + +/****************************************************************************** +** Functions +******************************************************************************/ + +/******************************************************************************* +** +** Function bthc_signal_event +** +** Description Perform context switch to bt_hc main thread +** +** Returns None +** +*******************************************************************************/ +extern void bthc_signal_event(uint16_t event); + +#endif /* BT_HCI_BDROID_H */ diff --git a/hci/include/bt_hci_lib.h b/hci/include/bt_hci_lib.h new file mode 100644 index 0000000..468e513 --- /dev/null +++ b/hci/include/bt_hci_lib.h @@ -0,0 +1,202 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef BT_HCI_LIB_H +#define BT_HCI_LIB_H + +#include <stdint.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +/** Struct types */ + + +/** Typedefs and defines */ + +/* Generic purpose transac returned upon request complete */ +typedef void* TRANSAC; + +/** Bluetooth Power Control States */ +typedef enum { + BT_HC_CHIP_PWR_OFF, + BT_HC_CHIP_PWR_ON, +} bt_hc_chip_power_state_t; + +/** Bluetooth Low Power Mode */ +typedef enum { + BT_HC_LPM_DISABLE, + BT_HC_LPM_ENABLE, + BT_HC_LPM_WAKE_ASSERT, + BT_HC_LPM_WAKE_DEASSERT, +} bt_hc_low_power_event_t; + +/** Receive flow control */ +typedef enum { + BT_RXFLOW_OFF, /* add transport device fd to select set */ + BT_RXFLOW_ON, /* remove transport device to from select set */ +} bt_rx_flow_state_t; + +/** HCI logging control */ +typedef enum { + BT_HC_LOGGING_OFF, + BT_HC_LOGGING_ON, +} bt_hc_logging_state_t; + +/** Result of write request */ +typedef enum { + BT_HC_TX_SUCCESS, /* a buffer is fully processed and can be released */ + BT_HC_TX_FAIL, /* transmit fail */ + BT_HC_TX_FRAGMENT, /* send split ACL pkt back to stack to reprocess */ +} bt_hc_transmit_result_t; + +/** Result of preload initialization */ +typedef enum { + BT_HC_PRELOAD_SUCCESS, + BT_HC_PRELOAD_FAIL, +} bt_hc_preload_result_t; + +/** Result of postload initialization */ +typedef enum { + BT_HC_POSTLOAD_SUCCESS, + BT_HC_POSTLOAD_FAIL, +} bt_hc_postload_result_t; + +/** Result of low power enable/disable request */ +typedef enum { + BT_HC_LPM_DISABLED, + BT_HC_LPM_ENABLED, +} bt_hc_lpm_request_result_t; + +/** Host/Controller Library Return Status */ +typedef enum { + BT_HC_STATUS_SUCCESS, + BT_HC_STATUS_FAIL, + BT_HC_STATUS_NOT_READY, + BT_HC_STATUS_NOMEM, + BT_HC_STATUS_BUSY, + BT_HC_STATUS_CORRUPTED_BUFFER +} bt_hc_status_t; + + +/* Section comment */ + +/* + * Bluetooth Host/Controller callback structure. + */ + +/* called upon bt host wake signal */ +typedef void (*hostwake_ind_cb)(bt_hc_low_power_event_t event); + +/* preload initialization callback */ +typedef void (*preload_result_cb)(TRANSAC transac, bt_hc_preload_result_t result); + +/* postload initialization callback */ +typedef void (*postload_result_cb)(TRANSAC transac, bt_hc_postload_result_t result); + +/* lpm enable/disable callback */ +typedef void (*lpm_result_cb)(bt_hc_lpm_request_result_t result); + +/* datapath buffer allocation callback (callout) */ +typedef char* (*alloc_mem_cb)(int size); + +/* datapath buffer deallocation callback (callout) */ +typedef int (*dealloc_mem_cb)(TRANSAC transac, char *p_buf); + +/* transmit result callback */ +typedef int (*tx_result_cb)(TRANSAC transac, char *p_buf, bt_hc_transmit_result_t result); + +/* a previously setup buffer is read and available for processing + buffer is deallocated in stack when processed */ +typedef int (*data_ind_cb)(TRANSAC transac, char *p_buf, int len); + +typedef struct { + /** set to sizeof(bt_hc_callbacks_t) */ + size_t size; + + /* notifies caller result of preload request */ + preload_result_cb preload_cb; + + /* notifies caller result of postload request */ + postload_result_cb postload_cb; + + /* notifies caller result of lpm enable/disable */ + lpm_result_cb lpm_cb; + + /* notifies hardware on host wake state */ + hostwake_ind_cb hostwake_ind; + + /* buffer allocation request */ + alloc_mem_cb alloc; + + /* buffer deallocation request */ + dealloc_mem_cb dealloc; + + /* notifies stack data is available */ + data_ind_cb data_ind; + + /* notifies caller when a buffer is transmitted (or failed) */ + tx_result_cb tx_result; +} bt_hc_callbacks_t; + +/* + * Bluetooth Host/Controller Interface + */ +typedef struct { + /** Set to sizeof(bt_hc_interface_t) */ + size_t size; + + /** + * Opens the interface and provides the callback routines + * to the implemenation of this interface. + */ + int (*init)(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr); + + /** Chip power control */ + void (*set_power)(bt_hc_chip_power_state_t state); + + /** Set low power mode wake */ + int (*lpm)(bt_hc_low_power_event_t event); + + /** Called prior to stack initialization */ + void (*preload)(TRANSAC transac); + + /** Called post stack initialization */ + void (*postload)(TRANSAC transac); + + /** Transmit buffer */ + int (*transmit_buf)(TRANSAC transac, char *p_buf, int len); + + /** Controls receive flow */ + int (*set_rxflow)(bt_rx_flow_state_t state); + + /** Controls HCI logging on/off */ + int (*logging)(bt_hc_logging_state_t state, char *p_path); + + /** Closes the interface */ + void (*cleanup)( void ); +} bt_hc_interface_t; + + +/* + * External shared lib functions + */ + +extern const bt_hc_interface_t* bt_hc_get_interface(void); + +#endif /* BT_HCI_LIB_H */ + diff --git a/hci/include/bt_vendor_lib.h b/hci/include/bt_vendor_lib.h new file mode 100644 index 0000000..054e317 --- /dev/null +++ b/hci/include/bt_vendor_lib.h @@ -0,0 +1,323 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef BT_VENDOR_LIB_H +#define BT_VENDOR_LIB_H + +#include <stdint.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +/** Struct types */ + + +/** Typedefs and defines */ + +/** Vendor specific operations OPCODE */ +typedef enum { +/* [operation] + * Power on or off the BT Controller. + * [input param] + * A pointer to int type with content of bt_vendor_power_state_t. + * Typecasting conversion: (int *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_POWER_CTRL, + +/* [operation] + * Perform any vendor specific initialization or configuration + * on the BT Controller. This is called before stack initialization. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call fwcfg_cb to notify the stack of the completion of vendor + * specific initialization once it has been done. + */ + BT_VND_OP_FW_CFG, + +/* [operation] + * Perform any vendor specific SCO/PCM configuration on the BT Controller. + * This is called after stack initialization. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call scocfg_cb to notify the stack of the completion of vendor + * specific SCO configuration once it has been done. + */ + BT_VND_OP_SCO_CFG, + +/* [operation] + * Open UART port on where the BT Controller is attached. + * This is called before stack initialization. + * [input param] + * A pointer to int array type for open file descriptors. + * The mapping of HCI channel to fd slot in the int array is given in + * bt_vendor_hci_channels_t. + * And, it requires the vendor lib to fill up the content before returning + * the call. + * Typecasting conversion: (int (*)[]) param. + * [return] + * Numbers of opened file descriptors. + * Valid number: + * 1 - CMD/EVT/ACL-In/ACL-Out via the same fd (e.g. UART) + * 2 - CMD/EVT on one fd, and ACL-In/ACL-Out on the other fd + * 4 - CMD, EVT, ACL-In, ACL-Out are on their individual fd + * [callback] + * None. + */ + BT_VND_OP_USERIAL_OPEN, + +/* [operation] + * Close the previously opened UART port. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_USERIAL_CLOSE, + +/* [operation] + * Get the LPM idle timeout in milliseconds. + * The stack uses this information to launch a timer delay before it + * attempts to de-assert LPM WAKE signal once downstream HCI packet + * has been delivered. + * [input param] + * A pointer to uint32_t type which is passed in by the stack. And, it + * requires the vendor lib to fill up the content before returning + * the call. + * Typecasting conversion: (uint32_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_GET_LPM_IDLE_TIMEOUT, + +/* [operation] + * Enable or disable LPM mode on BT Controller. + * [input param] + * A pointer to uint8_t type with content of bt_vendor_lpm_mode_t. + * Typecasting conversion: (uint8_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * Must call lpm_cb to notify the stack of the completion of LPM + * disable/enable process once it has been done. + */ + BT_VND_OP_LPM_SET_MODE, + +/* [operation] + * Assert or Deassert LPM WAKE on BT Controller. + * [input param] + * A pointer to uint8_t type with content of bt_vendor_lpm_wake_state_t. + * Typecasting conversion: (uint8_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_LPM_WAKE_SET_STATE, +} bt_vendor_opcode_t; + +/** Power on/off control states */ +typedef enum { + BT_VND_PWR_OFF, + BT_VND_PWR_ON, +} bt_vendor_power_state_t; + +/** Define HCI channel identifier in the file descriptors array + used in BT_VND_OP_USERIAL_OPEN operation. + */ +typedef enum { + CH_CMD, // HCI Command channel + CH_EVT, // HCI Event channel + CH_ACL_OUT, // HCI ACL downstream channel + CH_ACL_IN, // HCI ACL upstream channel + + CH_MAX // Total channels +} bt_vendor_hci_channels_t; + +/** LPM disable/enable request */ +typedef enum { + BT_VND_LPM_DISABLE, + BT_VND_LPM_ENABLE, +} bt_vendor_lpm_mode_t; + +/** LPM WAKE set state request */ +typedef enum { + BT_VND_LPM_WAKE_ASSERT, + BT_VND_LPM_WAKE_DEASSERT, +} bt_vendor_lpm_wake_state_t; + +/** Callback result values */ +typedef enum { + BT_VND_OP_RESULT_SUCCESS, + BT_VND_OP_RESULT_FAIL, +} bt_vendor_op_result_t; + +/* + * Bluetooth Host/Controller Vendor callback structure. + */ + +/* vendor initialization/configuration callback */ +typedef void (*cfg_result_cb)(bt_vendor_op_result_t result); + +/* datapath buffer allocation callback (callout) + * + * Vendor lib needs to request a buffer through the alloc callout function + * from HCI lib if the buffer is for constructing a HCI Command packet which + * will be sent through xmit_cb to BT Controller. + * + * For each buffer allocation, the requested size needs to be big enough to + * accommodate the below header plus a complete HCI packet -- + * typedef struct + * { + * uint16_t event; + * uint16_t len; + * uint16_t offset; + * uint16_t layer_specific; + * } HC_BT_HDR; + * + * HCI lib returns a pointer to the buffer where Vendor lib should use to + * construct a HCI command packet as below format: + * + * -------------------------------------------- + * | HC_BT_HDR | HCI command | + * -------------------------------------------- + * where + * HC_BT_HDR.event = 0x2000; + * HC_BT_HDR.len = Length of HCI command; + * HC_BT_HDR.offset = 0; + * HC_BT_HDR.layer_specific = 0; + * + * For example, a HCI_RESET Command will be formed as + * ------------------------ + * | HC_BT_HDR |03|0c|00| + * ------------------------ + * with + * HC_BT_HDR.event = 0x2000; + * HC_BT_HDR.len = 3; + * HC_BT_HDR.offset = 0; + * HC_BT_HDR.layer_specific = 0; + */ +typedef void* (*malloc_cb)(int size); + +/* datapath buffer deallocation callback (callout) */ +typedef void (*mdealloc_cb)(void *p_buf); + +/* define callback of the cmd_xmit_cb + * + * The callback function which HCI lib will call with the return of command + * complete packet. Vendor lib is responsible for releasing the buffer passed + * in at the p_mem parameter by calling dealloc callout function. + */ +typedef void (*tINT_CMD_CBACK)(void *p_mem); + +/* hci command packet transmit callback (callout) + * + * Vendor lib calls xmit_cb callout function in order to send a HCI Command + * packet to BT Controller. The buffer carrying HCI Command packet content + * needs to be first allocated through the alloc callout function. + * HCI lib will release the buffer for Vendor lib once it has delivered the + * packet content to BT Controller. + * + * Vendor lib needs also provide a callback function (p_cback) which HCI lib + * will call with the return of command complete packet. + * + * The opcode parameter gives the HCI OpCode (combination of OGF and OCF) of + * HCI Command packet. For example, opcode = 0x0c03 for the HCI_RESET command + * packet. + */ +typedef uint8_t (*cmd_xmit_cb)(uint16_t opcode, void *p_buf, tINT_CMD_CBACK p_cback); + +typedef struct { + /** set to sizeof(bt_vendor_callbacks_t) */ + size_t size; + + /* + * Callback and callout functions have implemented in HCI libray + * (libbt-hci.so). + */ + + /* notifies caller result of firmware configuration request */ + cfg_result_cb fwcfg_cb; + + /* notifies caller result of sco configuration request */ + cfg_result_cb scocfg_cb; + + /* notifies caller result of lpm enable/disable */ + cfg_result_cb lpm_cb; + + /* buffer allocation request */ + malloc_cb alloc; + + /* buffer deallocation request */ + mdealloc_cb dealloc; + + /* hci command packet transmit request */ + cmd_xmit_cb xmit_cb; +} bt_vendor_callbacks_t; + +/* + * Bluetooth Host/Controller VENDOR Interface + */ +typedef struct { + /** Set to sizeof(bt_vndor_interface_t) */ + size_t size; + + /* + * Functions need to be implemented in Vendor libray (libbt-vendor.so). + */ + + /** + * Caller will open the interface and pass in the callback routines + * to the implemenation of this interface. + */ + int (*init)(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr); + + /** Vendor specific operations */ + int (*op)(bt_vendor_opcode_t opcode, void *param); + + /** Closes the interface */ + void (*cleanup)(void); +} bt_vendor_interface_t; + + +/* + * External shared lib functions/data + */ + +/* Entry point of DLib -- + * Vendor library needs to implement the body of bt_vendor_interface_t + * structure and uses the below name as the variable name. HCI library + * will use this symbol name to get address of the object through the + * dlsym call. + */ +extern const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE; + +#endif /* BT_VENDOR_LIB_H */ + diff --git a/hci/include/hci.h b/hci/include/hci.h new file mode 100644 index 0000000..0bfec2b --- /dev/null +++ b/hci/include/hci.h @@ -0,0 +1,86 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/****************************************************************************** + * + * Filename: hci.h + * + * Description: Contains definitions used for HCI transport controls + * + ******************************************************************************/ + +#ifndef HCI_H +#define HCI_H + +/****************************************************************************** +** Constants & Macros +******************************************************************************/ + +/****************************************************************************** +** Type definitions +******************************************************************************/ + +/** Prototypes for HCI Service interface functions **/ + +/* Initialize transport's control block */ +typedef void (*tHCI_INIT)(void); + +/* Do transport's control block clean-up */ +typedef void (*tHCI_CLEANUP)(void); + +/* Send HCI command/data to the transport */ +typedef void (*tHCI_SEND)(HC_BT_HDR *p_msg); + +/* Handler for HCI upstream path */ +typedef uint16_t (*tHCI_RCV)(void); + +/* Callback function for the returned event of internally issued command */ +typedef void (*tINT_CMD_CBACK)(void *p_mem); + +/* Handler for sending HCI command from the local module */ +typedef uint8_t (*tHCI_SEND_INT)(uint16_t opcode, HC_BT_HDR *p_buf, \ + tINT_CMD_CBACK p_cback); + +/* Handler for getting acl data length */ +typedef void (*tHCI_ACL_DATA_LEN_HDLR)(void); + +/****************************************************************************** +** Extern variables and functions +******************************************************************************/ + +typedef struct { + tHCI_INIT init; + tHCI_CLEANUP cleanup; + tHCI_SEND send; + tHCI_SEND_INT send_int_cmd; + tHCI_ACL_DATA_LEN_HDLR get_acl_max_len; +#ifdef HCI_USE_MCT + tHCI_RCV evt_rcv; + tHCI_RCV acl_rcv; +#else + tHCI_RCV rcv; +#endif +} tHCI_IF; + +/****************************************************************************** +** Functions +******************************************************************************/ + + +#endif /* HCI_H */ + diff --git a/hci/include/userial.h b/hci/include/userial.h new file mode 100644 index 0000000..d3a5480 --- /dev/null +++ b/hci/include/userial.h @@ -0,0 +1,141 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/****************************************************************************** + * + * Filename: userial.h + * + * Description: Contains definitions used for serial port controls + * + ******************************************************************************/ + +#ifndef USERIAL_H +#define USERIAL_H + +/****************************************************************************** +** Constants & Macros +******************************************************************************/ + +/**** port IDs ****/ +#define USERIAL_PORT_1 0 +#define USERIAL_PORT_2 1 +#define USERIAL_PORT_3 2 +#define USERIAL_PORT_4 3 +#define USERIAL_PORT_5 4 +#define USERIAL_PORT_6 5 +#define USERIAL_PORT_7 6 +#define USERIAL_PORT_8 7 +#define USERIAL_PORT_9 8 +#define USERIAL_PORT_10 9 +#define USERIAL_PORT_11 10 +#define USERIAL_PORT_12 11 +#define USERIAL_PORT_13 12 +#define USERIAL_PORT_14 13 +#define USERIAL_PORT_15 14 +#define USERIAL_PORT_16 15 +#define USERIAL_PORT_17 16 +#define USERIAL_PORT_18 17 + +typedef enum { + USERIAL_OP_INIT, + USERIAL_OP_RXFLOW_ON, + USERIAL_OP_RXFLOW_OFF, +} userial_ioctl_op_t; + +/****************************************************************************** +** Type definitions +******************************************************************************/ + +/****************************************************************************** +** Extern variables and functions +******************************************************************************/ + +/****************************************************************************** +** Functions +******************************************************************************/ + +/******************************************************************************* +** +** Function userial_init +** +** Description Initializes the userial driver +** +** Returns TRUE/FALSE +** +*******************************************************************************/ +uint8_t userial_init(void); + +/******************************************************************************* +** +** Function userial_open +** +** Description Open Bluetooth device with the port ID +** +** Returns TRUE/FALSE +** +*******************************************************************************/ +uint8_t userial_open(uint8_t port); + +/******************************************************************************* +** +** Function userial_read +** +** Description Read data from the userial port +** +** Returns Number of bytes actually read from the userial port and +** copied into p_data. This may be less than len. +** +*******************************************************************************/ +uint16_t userial_read(uint16_t msg_id, uint8_t *p_buffer, uint16_t len); + +/******************************************************************************* +** +** Function userial_write +** +** Description Write data to the userial port +** +** Returns Number of bytes actually written to the userial port. This +** may be less than len. +** +*******************************************************************************/ +uint16_t userial_write(uint16_t msg_id, uint8_t *p_data, uint16_t len); + +/******************************************************************************* +** +** Function userial_close +** +** Description Close the userial port +** +** Returns None +** +*******************************************************************************/ +void userial_close(void); + +/******************************************************************************* +** +** Function userial_ioctl +** +** Description ioctl inteface +** +** Returns None +** +*******************************************************************************/ +void userial_ioctl(userial_ioctl_op_t op, void *p_data); + +#endif /* USERIAL_H */ + diff --git a/hci/include/utils.h b/hci/include/utils.h new file mode 100644 index 0000000..0f1517c --- /dev/null +++ b/hci/include/utils.h @@ -0,0 +1,194 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/****************************************************************************** + * + * Filename: utils.h + * + * Description: Utility functions declaration + * + ******************************************************************************/ + +#ifndef UTILS_H +#define UTILS_H + +/****************************************************************************** +** Constants & Macros +******************************************************************************/ + +#define STREAM_TO_UINT16(u16, p) {u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); (p) += 2;} +#define UINT16_TO_STREAM(p, u16) {*(p)++ = (uint8_t)(u16); *(p)++ = (uint8_t)((u16) >> 8);} +#define UINT32_TO_STREAM(p, u32) {*(p)++ = (uint8_t)(u32); *(p)++ = (uint8_t)((u32) >> 8); *(p)++ = (uint8_t)((u32) >> 16); *(p)++ = (uint8_t)((u32) >> 24);} + +/****************************************************************************** +** Type definitions +******************************************************************************/ + +typedef struct +{ + void *p_first; + void *p_last; + uint16_t count; +} BUFFER_Q; + +/****************************************************************************** +** Extern variables and functions +******************************************************************************/ + +/****************************************************************************** +** Functions +******************************************************************************/ + +/******************************************************************************* +** +** Function utils_init +** +** Description Utils initialization +** +** Returns None +** +*******************************************************************************/ +void utils_init (); + +/******************************************************************************* +** +** Function utils_cleanup +** +** Description Utils cleanup +** +** Returns None +** +*******************************************************************************/ +void utils_cleanup (); + +/******************************************************************************* +** +** Function utils_queue_init +** +** Description Initialize the given buffer queue +** +** Returns None +** +*******************************************************************************/ +void utils_queue_init (BUFFER_Q *p_q); + +/******************************************************************************* +** +** Function utils_enqueue +** +** Description Enqueue a buffer at the tail of the given queue +** +** Returns None +** +*******************************************************************************/ +void utils_enqueue (BUFFER_Q *p_q, void *p_buf); + +/******************************************************************************* +** +** Function utils_dequeue +** +** Description Dequeues a buffer from the head of the given queue +** +** Returns NULL if queue is empty, else buffer +** +*******************************************************************************/ +void *utils_dequeue (BUFFER_Q *p_q); + +/******************************************************************************* +** +** Function utils_dequeue_unlocked +** +** Description Dequeues a buffer from the head of the given queue without lock +** +** Returns NULL if queue is empty, else buffer +** +*******************************************************************************/ +void *utils_dequeue_unlocked (BUFFER_Q *p_q); + +/******************************************************************************* +** +** Function utils_getnext +** +** Description Return a pointer to the next buffer linked to the given buffer +** +** Returns NULL if the given buffer does not point to any next buffer, +** else next buffer address +** +*******************************************************************************/ +void *utils_getnext (void *p_buf); + +/******************************************************************************* +** +** Function utils_remove_from_queue +** +** Description Dequeue the given buffer from the middle of the given queue +** +** Returns NULL if the given queue is empty, else the given buffer +** +*******************************************************************************/ +void *utils_remove_from_queue (BUFFER_Q *p_q, void *p_buf); + +/******************************************************************************* +** +** Function utils_remove_from_queue_unlocked +** +** Description Dequeue the given buffer from the middle of the given queue without lock +** +** Returns NULL if the given queue is empty, else the given buffer +** +*******************************************************************************/ +void *utils_remove_from_queue_unlocked (BUFFER_Q *p_q, void *p_buf); + + +/******************************************************************************* +** +** Function utils_delay +** +** Description sleep unconditionally for timeout milliseconds +** +** Returns None +** +*******************************************************************************/ +void utils_delay (uint32_t timeout); + +/******************************************************************************* +** +** Function utils_lock +** +** Description application calls this function before entering critical +** section +** +** Returns None +** +*******************************************************************************/ +void utils_lock (void); + +/******************************************************************************* +** +** Function utils_unlock +** +** Description application calls this function when leaving critical +** section +** +** Returns None +** +*******************************************************************************/ +void utils_unlock (void); + +#endif /* UTILS_H */ + |