summaryrefslogtreecommitdiffstats
path: root/hci/src/hci_h4.c
diff options
context:
space:
mode:
Diffstat (limited to 'hci/src/hci_h4.c')
-rw-r--r--hci/src/hci_h4.c161
1 files changed, 89 insertions, 72 deletions
diff --git a/hci/src/hci_h4.c b/hci/src/hci_h4.c
index 36c692a..6a1c746 100644
--- a/hci/src/hci_h4.c
+++ b/hci/src/hci_h4.c
@@ -3,44 +3,44 @@
* Copyright (C) 2009-2012 Broadcom Corporation
*
* This program is the proprietary software of Broadcom Corporation and/or its
- * licensors, and may only be used, duplicated, modified or distributed
- * pursuant to the terms and conditions of a separate, written license
- * agreement executed between you and Broadcom (an "Authorized License").
- * Except as set forth in an Authorized License, Broadcom grants no license
- * (express or implied), right to use, or waiver of any kind with respect to
- * the Software, and Broadcom expressly reserves all rights in and to the
- * Software and all intellectual property rights therein.
- * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS
+ * licensors, and may only be used, duplicated, modified or distributed
+ * pursuant to the terms and conditions of a separate, written license
+ * agreement executed between you and Broadcom (an "Authorized License").
+ * Except as set forth in an Authorized License, Broadcom grants no license
+ * (express or implied), right to use, or waiver of any kind with respect to
+ * the Software, and Broadcom expressly reserves all rights in and to the
+ * Software and all intellectual property rights therein.
+ * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS
* SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
- * ALL USE OF THE SOFTWARE.
+ * ALL USE OF THE SOFTWARE.
*
* Except as expressly set forth in the Authorized License,
*
- * 1. This program, including its structure, sequence and organization,
- * constitutes the valuable trade secrets of Broadcom, and you shall
- * use all reasonable efforts to protect the confidentiality thereof,
- * and to use this information only in connection with your use of
+ * 1. This program, including its structure, sequence and organization,
+ * constitutes the valuable trade secrets of Broadcom, and you shall
+ * use all reasonable efforts to protect the confidentiality thereof,
+ * and to use this information only in connection with your use of
* Broadcom integrated circuit products.
*
- * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED
- * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
- * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
- * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY
- * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
- * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
- * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
+ * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED
+ * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
+ * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
+ * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY
+ * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
+ * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
+ * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
* CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT
* OF USE OR PERFORMANCE OF THE SOFTWARE.
*
* 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR
- * ITS LICENSORS BE LIABLE FOR
- * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY
- * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO
- * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM
- * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR
- * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE
- * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
- * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF
+ * ITS LICENSORS BE LIABLE FOR
+ * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY
+ * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO
+ * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM
+ * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR
+ * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE
+ * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
+ * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF
* ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.
*
******************************************************************************/
@@ -59,6 +59,7 @@
#include <stdlib.h>
#include <fcntl.h>
#include "bt_hci_bdroid.h"
+#include "hci.h"
#include "userial.h"
#include "utils.h"
@@ -66,14 +67,14 @@
** Constants & Macros
******************************************************************************/
-#ifndef HCIH4_DBG
-#define HCIH4_DBG FALSE
+#ifndef HCI_DBG
+#define HCI_DBG FALSE
#endif
-#if (HCIH4_DBG == TRUE)
-#define HCIH4DBG(param, ...) {LOGD(param, ## __VA_ARGS__);}
+#if (HCI_DBG == TRUE)
+#define HCIDBG(param, ...) {LOGD(param, ## __VA_ARGS__);}
#else
-#define HCIH4DBG(param, ...) {}
+#define HCIDBG(param, ...) {}
#endif
/* Preamble length for HCI Commands:
@@ -124,7 +125,7 @@ static const uint16_t msg_evt_table[] =
#define L2CAP_HEADER_SIZE 4
/* Maximum numbers of allowed internal
-** outstanding command packets at any time
+** outstanding command packets at any time
*/
#define INT_CMD_PKT_MAX_COUNT 8
#define INT_CMD_PKT_IDX_MASK 0x07
@@ -152,8 +153,8 @@ typedef void (*tINT_CMD_CBACK)(void *p_mem);
typedef struct
{
uint16_t opcode; /* OPCODE of outstanding internal commands */
- tINT_CMD_CBACK cback; /* Callback function when return of internal
- * command is received */
+ tINT_CMD_CBACK cback; /* Callback function when return of internal
+ * command is received */
} tINT_CMD_Q;
/* Control block for HCISU_H4 */
@@ -211,8 +212,8 @@ static tHCI_H4_CB h4_cb;
** Function get_acl_data_length_cback
**
** Description Callback function for HCI_READ_BUFFER_SIZE and
-** HCI_LE_READ_BUFFER_SIZE commands if they were sent because
-** of internal request.
+** HCI_LE_READ_BUFFER_SIZE commands if they were sent because
+** of internal request.
**
** Returns None
**
@@ -271,9 +272,9 @@ void get_acl_data_length_cback(void *p_mem)
** Function internal_event_intercept
**
** Description This function is called to parse received HCI event and
-** - update the Num_HCI_Command_Packets
-** - intercept the event if it is the result of an early
-** issued internal command.
+** - update the Num_HCI_Command_Packets
+** - intercept the event if it is the result of an early
+** issued internal command.
**
** Returns TRUE : if the event had been intercepted for internal process
** FALSE : send this event to core stack
@@ -301,7 +302,7 @@ uint8_t internal_event_intercept(void)
if (opcode == p_cb->int_cmd[p_cb->int_cmd_rd_idx].opcode)
{
- HCIH4DBG( \
+ HCIDBG( \
"Intercept CommandCompleteEvent for internal command (0x%04X)",\
opcode);
if (p_cb->int_cmd[p_cb->int_cmd_rd_idx].cback != NULL)
@@ -337,12 +338,12 @@ uint8_t internal_event_intercept(void)
**
** Function acl_rx_frame_buffer_alloc
**
-** Description This function is called from the HCI transport when the
+** Description This function is called from the HCI transport when the
** first 4 or 6 bytes of an HCI ACL packet have been received:
-** - Allocate a new buffer if it is a start pakcet of L2CAP
+** - Allocate a new buffer if it is a start pakcet of L2CAP
** message.
-** - Return the buffer address of the starting L2CAP message
-** frame if the packet is the next segment of a fragmented
+** - Return the buffer address of the starting L2CAP message
+** frame if the packet is the next segment of a fragmented
** L2CAP message.
**
** Returns the address of the receive buffer H4 RX should use
@@ -465,8 +466,8 @@ static HC_BT_HDR *acl_rx_frame_buffer_alloc (void)
** Function acl_rx_frame_end_chk
**
** Description This function is called from the HCI transport when the last
-** byte of an HCI ACL packet has been received. It checks if
-** the L2CAP message is complete, i.e. no more continuation
+** byte of an HCI ACL packet has been received. It checks if
+** the L2CAP message is complete, i.e. no more continuation
** packets are expected.
**
** Returns TRUE if message complete, FALSE if continuation expected
@@ -478,7 +479,7 @@ static uint8_t acl_rx_frame_end_chk (void)
uint16_t handle, hci_len, l2cap_len;
HC_BT_HDR *p_buf;
tHCI_H4_CB *p_cb = &h4_cb;
- uint8_t frame_end=TRUE;
+ uint8_t frame_end=TRUE;
p_buf = p_cb->p_rcv_msg;
p = (uint8_t *)(p_buf + 1);
@@ -491,7 +492,7 @@ static uint8_t acl_rx_frame_end_chk (void)
{
if (l2cap_len > (p_buf->len-(HCI_ACL_PREAMBLE_SIZE+L2CAP_HEADER_SIZE)) )
{
- /* If the L2CAP length has not been reached, tell H4 not to send
+ /* If the L2CAP length has not been reached, tell H4 not to send
* this buffer to stack */
frame_end = FALSE;
}
@@ -506,8 +507,8 @@ static uint8_t acl_rx_frame_end_chk (void)
}
}
- /****
- ** Print snoop trace
+ /****
+ ** Print snoop trace
****/
if (p_buf->offset)
{
@@ -532,7 +533,7 @@ static uint8_t acl_rx_frame_end_chk (void)
/* roll pointer back */
p = p - HCI_ACL_PREAMBLE_SIZE;
- /* adjust `p_buf->offset` & `p_buf->len`
+ /* adjust `p_buf->offset` & `p_buf->len`
* before calling btsnoop_capture() */
p_buf->offset = p_buf->offset - HCI_ACL_PREAMBLE_SIZE;
p_buf->len = p_buf->len - p_buf->offset;
@@ -574,7 +575,7 @@ static uint8_t acl_rx_frame_end_chk (void)
*******************************************************************************/
void hci_h4_init(void)
{
- HCIH4DBG("hci_h4_init");
+ HCIDBG("hci_h4_init");
memset(&h4_cb, 0, sizeof(tHCI_H4_CB));
utils_queue_init(&(h4_cb.acl_rx_q));
@@ -602,7 +603,7 @@ void hci_h4_init(void)
*******************************************************************************/
void hci_h4_cleanup(void)
{
- HCIH4DBG("hci_h4_cleanup");
+ HCIDBG("hci_h4_cleanup");
btsnoop_close();
btsnoop_cleanup();
@@ -662,7 +663,7 @@ void hci_h4_send_msg(HC_BT_HDR *p_msg)
/* Do all the first chunks */
while (p_msg->len > acl_pkt_size)
{
- /* remember layer_specific because uart borrow
+ /* remember layer_specific because uart borrow
one byte from layer_specific for packet type */
lay_spec = p_msg->layer_specific;
@@ -670,14 +671,14 @@ void hci_h4_send_msg(HC_BT_HDR *p_msg)
*p = type;
bytes_to_send = acl_pkt_size + 1; /* packet_size + message type */
- bytes_sent = userial_write((uint8_t *) p, bytes_to_send);
+ bytes_sent = userial_write(event,(uint8_t *) p,bytes_to_send);
/* generate snoop trace message */
btsnoop_capture(p_msg, FALSE);
p_msg->layer_specific = lay_spec;
/* Adjust offset and length for what we just sent */
- p_msg->offset += acl_data_size;
+ p_msg->offset += acl_data_size;
p_msg->len -= acl_data_size;
p = ((uint8_t *)(p_msg + 1)) + p_msg->offset;
@@ -715,7 +716,7 @@ void hci_h4_send_msg(HC_BT_HDR *p_msg)
}
- /* remember layer_specific because uart borrow
+ /* remember layer_specific because uart borrow
one byte from layer_specific for packet type */
lay_spec = p_msg->layer_specific;
@@ -724,7 +725,7 @@ void hci_h4_send_msg(HC_BT_HDR *p_msg)
*p = type;
bytes_to_send = p_msg->len + 1; /* message_size + message type */
- bytes_sent = userial_write((uint8_t *) p, bytes_to_send);
+ bytes_sent = userial_write(event,(uint8_t *) p, bytes_to_send);
p_msg->layer_specific = lay_spec;
@@ -733,7 +734,7 @@ void hci_h4_send_msg(HC_BT_HDR *p_msg)
num_hci_cmd_pkts--;
/* If this is an internal Cmd packet, the layer_specific field would
- * have stored with the opcode of HCI command.
+ * have stored with the opcode of HCI command.
* Retrieve the opcode from the Cmd packet.
*/
p++;
@@ -769,9 +770,10 @@ void hci_h4_send_msg(HC_BT_HDR *p_msg)
**
** Function hci_h4_receive_msg
**
-** Description
+** Description Construct HCI EVENT/ACL packets and send them to stack once
+** complete packet has been received.
**
-** Returns
+** Returns Number of read bytes
**
*******************************************************************************/
uint16_t hci_h4_receive_msg(void)
@@ -785,7 +787,7 @@ uint16_t hci_h4_receive_msg(void)
while (TRUE)
{
/* Read one byte to see if there is anything waiting to be read */
- if (userial_read(&byte, 1) == 0)
+ if (userial_read(0 /*dummy*/, &byte, 1) == 0)
{
break;
}
@@ -837,7 +839,7 @@ uint16_t hci_h4_receive_msg(void)
{
/*
* A start packet & with non-zero data payload length.
- * We want to read 2 more bytes to get L2CAP payload
+ * We want to read 2 more bytes to get L2CAP payload
* length.
*/
p_cb->rcv_len = 2;
@@ -847,15 +849,15 @@ uint16_t hci_h4_receive_msg(void)
}
/*
- * Check for segmented packets. If this is a continuation
- * packet, then we will continue appending data to the
+ * Check for segmented packets. If this is a continuation
+ * packet, then we will continue appending data to the
* original rcv buffer.
*/
p_cb->p_rcv_msg = acl_rx_frame_buffer_alloc();
}
else
{
- /* Received entire preamble.
+ /* Received entire preamble.
* Length is in the last received byte */
msg_len = byte;
p_cb->rcv_len = msg_len;
@@ -910,7 +912,7 @@ uint16_t hci_h4_receive_msg(void)
}
else
{
- /* Message has no additional parameters.
+ /* Message has no additional parameters.
* (Entire message has been received) */
if (p_cb->rcv_msg_type == H4_TYPE_ACL_DATA)
acl_rx_frame_end_chk(); /* to print snoop trace */
@@ -930,7 +932,7 @@ uint16_t hci_h4_receive_msg(void)
if (p_cb->rcv_len > 0)
{
/* Read in the rest of the message */
- len = userial_read( \
+ len = userial_read(0 /*dummy*/, \
((uint8_t *)(p_cb->p_rcv_msg+1) + p_cb->p_rcv_msg->len), \
p_cb->rcv_len);
p_cb->p_rcv_msg->len += len;
@@ -981,13 +983,13 @@ uint16_t hci_h4_receive_msg(void)
/* generate snoop trace message */
/* ACL packet tracing had done in acl_rx_frame_end_chk() */
- if (p_cb->p_rcv_msg->event != MSG_HC_TO_STACK_HCI_ACL)
+ if (p_cb->p_rcv_msg->event != MSG_HC_TO_STACK_HCI_ACL)
btsnoop_capture(p_cb->p_rcv_msg, TRUE);
if (p_cb->p_rcv_msg->event == MSG_HC_TO_STACK_HCI_EVT)
intercepted = internal_event_intercept();
- if ((bt_hc_cbacks) && (intercepted == FALSE))
+ if ((bt_hc_cbacks) && (intercepted == FALSE))
{
bt_hc_cbacks->data_ind((TRANSAC) p_cb->p_rcv_msg, \
(char *) (p_cb->p_rcv_msg + 1), \
@@ -1085,3 +1087,18 @@ void hci_h4_get_acl_data_length(void)
}
}
+
+/******************************************************************************
+** HCI H4 Services interface table
+******************************************************************************/
+
+const tHCI_IF hci_h4_func_table =
+{
+ hci_h4_init,
+ hci_h4_cleanup,
+ hci_h4_send_msg,
+ hci_h4_send_int_cmd,
+ hci_h4_get_acl_data_length,
+ hci_h4_receive_msg
+};
+