mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
wireless/bluetooth: decoupling bt_driver_s and bt_buf_s
Change-Id: I12879c364cf8ca63898da94621e94d8fc23a4f6f Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
@@ -991,7 +991,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");
|
||||
@@ -1486,18 +1486,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);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -1513,7 +1507,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);
|
||||
@@ -1563,7 +1557,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);
|
||||
|
||||
@@ -1594,13 +1588,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
|
||||
@@ -1620,26 +1614,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. */
|
||||
@@ -1668,7 +1670,7 @@ void bt_hci_receive(FAR struct bt_buf_s *buf)
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1690,6 +1692,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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1272,7 +1272,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;
|
||||
@@ -1355,6 +1355,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
|
||||
|
||||
Reference in New Issue
Block a user