include/nuttx/wireless/bluetooth adn include/nuttx/wireless/bluetooth: Add SIOCBTCONNECT and SIOCBTDISCONNECT ioctl commands

This commit is contained in:
Lwazi Dube
2018-12-02 10:57:51 -06:00
committed by Gregory Nutt
parent ab974488d5
commit b7fa409fc4
4 changed files with 90 additions and 2 deletions
+21
View File
@@ -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;
}
+50
View File
@@ -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.
*