wireless/bluetooth: decoupling bt_driver_s and bt_buf_s

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an
2021-05-18 21:45:01 +08:00
committed by Matias N
parent 6837d4e1ba
commit 6c69b12000
10 changed files with 344 additions and 395 deletions
+25 -21
View File
@@ -992,7 +992,7 @@ static void hci_event(FAR struct bt_buf_s *buf)
static int hci_tx_kthread(int argc, FAR char *argv[])
{
FAR const struct bt_driver_s *btdev = g_btdev.btdev;
FAR struct bt_driver_s *btdev = g_btdev.btdev;
int ret;
wlinfo("started\n");
@@ -1487,18 +1487,12 @@ static void cmd_queue_init(void)
*
****************************************************************************/
int bt_send(FAR const struct bt_driver_s *btdev,
int bt_send(FAR struct bt_driver_s *btdev,
FAR struct bt_buf_s *buf)
{
int ret;
/* Send to driver */
ret = btdev->send(btdev, buf);
/* TODO: Hook here to notify hci monitor */
return ret;
return btdev->send(btdev, buf->type, buf->data, buf->len);
}
/****************************************************************************
@@ -1514,7 +1508,7 @@ int bt_send(FAR const struct bt_driver_s *btdev,
int bt_initialize(void)
{
FAR const struct bt_driver_s *btdev = g_btdev.btdev;
FAR struct bt_driver_s *btdev = g_btdev.btdev;
int ret;
wlinfo("btdev %p\n", btdev);
@@ -1564,7 +1558,7 @@ int bt_initialize(void)
*
****************************************************************************/
int bt_driver_register(FAR const struct bt_driver_s *btdev)
int bt_driver_register(FAR struct bt_driver_s *btdev)
{
DEBUGASSERT(btdev != NULL && btdev->open != NULL && btdev->send != NULL);
@@ -1595,13 +1589,13 @@ int bt_driver_register(FAR const struct bt_driver_s *btdev)
*
****************************************************************************/
void bt_driver_unregister(FAR const struct bt_driver_s *btdev)
void bt_driver_unregister(FAR struct bt_driver_s *btdev)
{
g_btdev.btdev = NULL;
}
/****************************************************************************
* Name: bt_hci_receive
* Name: bt_receive
*
* Description:
* Called by the Bluetooth low-level driver when new data is received from
@@ -1621,26 +1615,34 @@ void bt_driver_unregister(FAR const struct bt_driver_s *btdev)
*
****************************************************************************/
/* TODO: rename to bt_receive? */
void bt_hci_receive(FAR struct bt_buf_s *buf)
int bt_receive(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type,
FAR void *data, size_t len)
{
FAR struct bt_hci_evt_hdr_s *hdr;
struct bt_buf_s *buf;
int ret;
wlinfo("buf %p len %u\n", buf, buf->len);
wlinfo("data %p len %zu\n", data, len);
/* Critical command complete/status events use the high priority work
* queue.
*/
if (buf->type != BT_ACL_IN)
buf = bt_buf_alloc(type, NULL, 0);
if (buf == NULL)
{
if (buf->type != BT_EVT)
return -ENOMEM;
}
memcpy(bt_buf_extend(buf, len), data, len);
if (type != BT_ACL_IN)
{
if (type != BT_EVT)
{
wlerr("ERROR: Invalid buf type %u\n", buf->type);
bt_buf_release(buf);
return;
return -EINVAL;
}
/* Command Complete/Status events use high priority messages. */
@@ -1669,7 +1671,7 @@ void bt_hci_receive(FAR struct bt_buf_s *buf)
}
}
return;
return OK;
}
}
@@ -1691,6 +1693,8 @@ void bt_hci_receive(FAR struct bt_buf_s *buf)
wlerr("ERROR: Failed to schedule LPWORK: %d\n", ret);
}
}
return OK;
}
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
+17 -4
View File
@@ -126,7 +126,7 @@ struct bt_dev_s
/* Registered HCI driver */
FAR const struct bt_driver_s *btdev;
FAR struct bt_driver_s *btdev;
};
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
@@ -281,7 +281,7 @@ int bt_initialize(void);
*
****************************************************************************/
int bt_driver_register(FAR const struct bt_driver_s *btdev);
int bt_driver_register(FAR struct bt_driver_s *btdev);
/****************************************************************************
* Name: bt_driver_unregister
@@ -300,7 +300,7 @@ int bt_driver_register(FAR const struct bt_driver_s *btdev);
*
****************************************************************************/
void bt_driver_unregister(FAR const struct bt_driver_s *btdev);
void bt_driver_unregister(FAR struct bt_driver_s *btdev);
/****************************************************************************
* Name: bt_send
@@ -318,7 +318,7 @@ void bt_driver_unregister(FAR const struct bt_driver_s *btdev);
*
****************************************************************************/
int bt_send(FAR const struct bt_driver_s *btdev,
int bt_send(FAR struct bt_driver_s *btdev,
FAR struct bt_buf_s *buf);
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
@@ -465,4 +465,17 @@ void bt_hci_cb_register(FAR struct bt_hci_cb_s *cb);
#endif
/****************************************************************************
* Name: bt_receive
*
* Description:
* Called by the Bluetooth low-level driver when new data is received from
* the radio. This may be called from the low-level driver and is part of
* the driver interface
*
****************************************************************************/
int bt_receive(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type,
FAR void *data, size_t len);
#endif /* __WIRELESS_BLUETOOTH_BT_HDICORE_H */
+3 -1
View File
@@ -1271,7 +1271,7 @@ static int btnet_properties(FAR struct radio_driver_s *netdev,
*
****************************************************************************/
int bt_netdev_register(FAR const struct bt_driver_s *btdev)
int bt_netdev_register(FAR struct bt_driver_s *btdev)
{
FAR struct btnet_driver_s *priv;
FAR struct radio_driver_s *radio;
@@ -1354,6 +1354,8 @@ int bt_netdev_register(FAR const struct bt_driver_s *btdev)
radio->r_req_data = btnet_req_data; /* Enqueue frame for transmission */
radio->r_properties = btnet_properties; /* Return radio properties */
btdev->receive = bt_receive;
/* Associate the driver in with the Bluetooth stack.
*
* REVISIT: We will eventually need to remember which Bluetooth device