Skip to content
Snippets Groups Projects
Commit 49644be9 authored by Gregory Nutt's avatar Gregory Nutt
Browse files

include/nuttx/wireless and wireless/bluetooth: Add support for an IOCTL...

include/nuttx/wireless and wireless/bluetooth:  Add support for an IOCTL command to enable Bluetooth security.
parent 9d3a06e5
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@
/* Bluetooth network device IOCTL commands. */
#ifndef WL_BLUETOOTHCMDS != 14
#ifndef WL_BLUETOOTHCMDS != 15
# error Incorrect setting for number of Bluetooth IOCTL commands
#endif
......@@ -91,6 +91,9 @@
* Read device statistics.
* SIOCZBTSTATS
* Read device statistics, and zero them.
*
* NOTE: These are here for reference. None of the NetBSD IOCTL commands
* have been implemented in NuttX.
*/
#define SIOCGBTINFO _WLIOC(WL_BLUETOOTHFIRST + 0)
......@@ -152,6 +155,15 @@
#define SIOCBT_SCANSTOP _WLIOC(WL_BLUETOOTHFIRST + 13)
/* SIOCBT_SECURITY
* Description: Enable security for a connection.
* Input: A reference to a write-able instance of struct
* bt_security_s.
* Output: None
*/
#define SIOCBT_SECURITY _WLIOC(WL_BLUETOOTHFIRST + 14)
/* Definitions associated with struct btreg_s *******************************/
/* struct btreq_s union field accessors */
......@@ -292,6 +304,15 @@ struct bt_scanresult_s
(sizeof(struct bt_scanresult_s) + \
((n) - 1) * sizeof(struct bt_scanresponse_s))
/* Read-only data that accompanies the SIOCBT_SECURITY IOCTL command */
struct bt_security_s
{
char se_name[HCI_DEVNAME_SIZE]; /* Device name */
bt_addr_le_t se_addr; /* BLE address */
enum bt_security_e se_level; /* Security level */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
......
......@@ -162,7 +162,7 @@
/* Reserved for Bluetooth network devices (see bt_ioctls.h) */
#define WL_BLUETOOTHFIRST (WL_NETFIRST + WL_NNETCMDS)
#define WL_BLUETOOTHCMDS (14)
#define WL_BLUETOOTHCMDS (15)
#define WL_IBLUETOOTHCMD(cmd) (_WLIOCVALID(cmd) && \
_IOC_NR(cmd) >= WL_BLUETOOTHFIRST && \
_IOC_NR(cmd) < (WL_BLUETOOTHFIRST + WL_BLUETOOTHCMDS))
......
......@@ -52,6 +52,7 @@
#include <nuttx/wireless/bt_ioctl.h>
#include "bt_hcicore.h"
#include "bt_conn.h"
#include "bt_ioctl.h"
#ifdef CONFIG_NETDEV_IOCTL /* Not optional! */
......@@ -216,7 +217,7 @@ static int btnet_scan_result(FAR struct bt_scanresult_s *result)
head = g_scanstate.bs_head;
tail = g_scanstate.bs_tail;
maxrsp = result->sc_nrsp;
maxrsp = result->sr_nrsp;
for (nrsp = 0; nrsp < maxrsp && head != tail; nrsp++)
{
......@@ -226,7 +227,7 @@ static int btnet_scan_result(FAR struct bt_scanresult_s *result)
/* Copy data from the head index into the user buffer */
src = (FAR const uint8_t *)&g_scanstate.bs_rsp[head];
dest = (FAR uint8_t *)&result->sc_rsp[nrsp];
dest = (FAR uint8_t *)&result->sr_rsp[nrsp];
memcpy(dest, src, sizeof(struct bt_scanresponse_s));
/* Increment the head index */
......@@ -238,7 +239,7 @@ static int btnet_scan_result(FAR struct bt_scanresult_s *result)
}
g_scanstate.bs_head = head;
result->sc_nrsp = nrsp;
result->sr_nrsp = nrsp;
nxsem_post(&g_scanstate.bs_exclsem);
return OK;
}
......@@ -403,6 +404,48 @@ int btnet_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg)
}
break;
/* SIOCBT_SECURITY
* Description: Enable security for a connection.
* Input: A reference to a write-able instance of struct
* bt_security_s.
* Output: None
*/
case SIOCBT_SECURITY:
{
FAR struct bt_security_s *sec =
(FAR struct bt_security_s *)((uintptr_t)arg);
if (sec == NULL)
{
ret = -EINVAL;
}
else
{
FAR struct bt_conn_s *conn;
/* Get the connection associated with the provided LE address */
conn = bt_conn_lookup_addr_le(&sec->se_addr);
if (conn == NULL)
{
wlwarn("WARNING: Peer not connected\n");
ret = -ENOTCONN;
}
else
{
ret = bt_conn_security(conn, sec->se_level);
if (ret < 0)
{
wlerr("ERROR: Security setting failed: %d\n", ret);
}
bt_conn_release(conn);
}
}
}
break;
default:
wlwarn("WARNING: Unrecognized IOCTL command: %02x\n", cmd);
ret = -ENOTTY;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment