mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
include/nuttx/wireless/bluetooth adn include/nuttx/wireless/bluetooth: Add SIOCBTCONNECT and SIOCBTDISCONNECT ioctl commands
This commit is contained in:
@@ -132,6 +132,7 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
|
||||
{
|
||||
FAR struct bt_conn_s *conn;
|
||||
FAR struct bt_buf_s *buf;
|
||||
struct mq_attr attr;
|
||||
int ret;
|
||||
|
||||
/* Get the connection instance */
|
||||
@@ -189,6 +190,23 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
|
||||
do
|
||||
{
|
||||
buf = NULL;
|
||||
|
||||
/* Make sure the thread is not blocked forever on an empty queue.
|
||||
* SIOCBTCONNECT will fail if preceding SIOCBTDISCONNECT does not
|
||||
* result in a successful termination of this thread.
|
||||
*/
|
||||
|
||||
ret = mq_getattr(conn->tx_queue, &attr);
|
||||
if (ret != OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (attr.mq_curmsgs == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ret = bt_queue_receive(conn->tx_queue, &buf);
|
||||
if (ret >= 0)
|
||||
{
|
||||
@@ -201,6 +219,9 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
|
||||
bt_conn_reset_rx_state(conn);
|
||||
|
||||
wlinfo("handle %u exiting\n", conn->handle);
|
||||
|
||||
/* Release reference taken when thread was created */
|
||||
|
||||
bt_conn_release(conn);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -659,6 +659,56 @@ int btnet_ioctl(FAR struct net_driver_s *netdev, int cmd, unsigned long arg)
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case SIOCBTCONNECT:
|
||||
{
|
||||
FAR struct bt_conn_s *conn;
|
||||
conn = bt_conn_create_le(&btreq->btr_rmtpeer);
|
||||
|
||||
if (!conn)
|
||||
{
|
||||
wlerr("Connection failed\n");
|
||||
ret = -ENOTCONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
wlinfo("Connection pending\n");
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SIOCBTDISCONNECT:
|
||||
{
|
||||
FAR struct bt_conn_s *conn;
|
||||
|
||||
conn = bt_conn_lookup_addr_le(&btreq->btr_rmtpeer);
|
||||
if (!conn)
|
||||
{
|
||||
wlerr("Peer not connected\n");
|
||||
ret = -ENOTCONN;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
|
||||
if (ret == -ENOTCONN)
|
||||
{
|
||||
wlerr("Already disconnected\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Release reference taken in bt_conn_create_le */
|
||||
|
||||
bt_conn_release(conn);
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
/* Release reference taken in bt_conn_lookup_addr_le */
|
||||
|
||||
bt_conn_release(conn);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* SIOCGBTINFO: Get Bluetooth device Info. Given the device name,
|
||||
* fill in the btreq_s structure.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user