Bluetooth: Controller: Use net_buf for HCI RX

Instead of copying the net_buf contents into a temporary
buffer byte-by-byte, the Controller HCI code now handles
incoming commands and ACL packets from the Host directly
in the net_buf containers, to avoid unnecessary memory
copying and to align with the rest of the Bluetooth stack.

Jira: ZEP-726

Change-Id: I9802607d84ee6206218b711e7e6e23dafb70581a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
Carles Cufi 2016-09-20 12:36:44 +02:00 committed by Johan Hedberg
commit d12b6c87c9
3 changed files with 178 additions and 190 deletions

View file

@ -267,53 +267,24 @@ static void recv_fiber(int unused0, int unused1)
static int hci_driver_send(struct net_buf *buf)
{
uint8_t type;
uint8_t remaining;
uint8_t evt_len;
uint8_t *in;
int err;
BT_DBG("enter");
remaining = 0;
evt_len = 0;
err = hci_handle(buf, &evt_len, &in);
type = bt_buf_get_type(buf);
switch (type) {
case BT_BUF_ACL_OUT:
hcic_handle(HCI_ACL, &remaining, &in);
break;
case BT_BUF_CMD:
hcic_handle(HCI_CMD, &remaining, &in);
break;
default:
BT_ERR("Unknown HCI type %u", type);
return -EINVAL;
if (err) {
return err;
}
if (remaining || !buf->len) {
BT_ERR("Empty or Len greater than expected");
return -EINVAL;
}
if (buf->len) {
while (buf->len - 1) {
hcic_handle(net_buf_pull_u8(buf), &remaining, &in);
}
if (remaining) {
BT_ERR("Len greater than expected");
return -EINVAL;
}
hcic_handle(net_buf_pull_u8(buf), &remaining, &in);
BT_DBG("hcic_handle returned %u bytes", remaining);
if (remaining) {
int retval;
retval = evt_acl_create(remaining, in);
if (retval) {
return retval;
}
BT_DBG("hci_handle returned %u bytes", evt_len);
if (evt_len) {
err = evt_acl_create(evt_len, in);
if (err) {
return err;
}
}