zephyr/include/bluetooth/driver.h
Johan Hedberg 30601c09bb Bluetooth: Refactor buffer handling for non-host managed buffers
So far the assumption has been that the host stack manages all
incoming and outgoing buffers. For the incoming buffers (from the
controller) this has required hci_core.c to manage its own pools and
do the host flow control. This setup makes perfect sense for an
architecture where the controller resides remotely on a different CPU
& address space (i.e. the "traditional" HCI transport case).

When the stack runs on a system where the controller resides in the
same address space this setup doesn't work that well. In such a
scenario the incoming buffers are ideally created as low down in the
stack as possible (i.e. below HCI), which means that the current
hci_core.c cannot be responsible for managing their pools.

To allow for both types of architectures this patch introduces a new
BLUETOOTH_HOST_BUFFERS Kconfig option that can be selected to say that
host-side management is desired, or deselected to say that the
controller (residing in the same address space) takes care of managing
the incoming buffers.

So far the incoming buffer types were identified by hci_core.c by
looking at their "free pool" pointers, however as soon as the pools
are allowed to be somewhere else this doesn't work. To solve this we
now require a minimum user data size for all Bluetooth buffers and use
that to store the buffer type.

Change-Id: I14bc32007e3e3f17c654f71f79b520650028d7ce
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-11 11:52:29 +00:00

74 lines
1.8 KiB
C

/** @file
* @brief Bluetooth HCI driver API.
*/
/*
* Copyright (c) 2015 Intel 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_DRIVER_H
#define __BT_DRIVER_H
#include <net/buf.h>
#include <bluetooth/buf.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(CONFIG_BLUETOOTH_HOST_BUFFERS)
/** Allocate a buffer for an HCI event
*
* This will set the BT_BUF_EVT buffer type so bt_buf_set_type()
* doesn't need to be explicitly called.
*
* @return A new buffer with the BT_BUF_EVT type.
*/
struct net_buf *bt_buf_get_evt(void);
/** Allocate a buffer for incoming ACL data
*
* This will set the BT_BUF_ACL_IN buffer type so bt_buf_set_type()
* doesn't need to be explicitly called.
*
* @return A new buffer with the BT_BUF_ACL_IN type.
*/
struct net_buf *bt_buf_get_acl(void);
#endif /* CONFIG_BLUETOOTH_HOST_BUFFERS */
/* Receive data from the controller/HCI driver */
int bt_recv(struct net_buf *buf);
struct bt_driver {
/* Open the HCI transport */
int (*open)(void);
/* Send HCI buffer to controller */
int (*send)(struct net_buf *buf);
};
/* Register a new HCI driver to the Bluetooth stack */
int bt_driver_register(struct bt_driver *drv);
/* Unregister a previously registered HCI driver */
void bt_driver_unregister(struct bt_driver *drv);
#ifdef __cplusplus
}
#endif
#endif /* __BT_DRIVER_H */