diff --git a/include/nuttx/wireless/bt_ioctl.h b/include/nuttx/wireless/bt_ioctl.h index c152d0e9b28..21f30e93c71 100644 --- a/include/nuttx/wireless/bt_ioctl.h +++ b/include/nuttx/wireless/bt_ioctl.h @@ -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 ****************************************************************************/ diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index f5681b4f7bf..2c9e62f59ca 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -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)) diff --git a/wireless/bluetooth/bt_ioctl.c b/wireless/bluetooth/bt_ioctl.c index 98f3f4293b4..cab370d502f 100644 --- a/wireless/bluetooth/bt_ioctl.c +++ b/wireless/bluetooth/bt_ioctl.c @@ -52,6 +52,7 @@ #include #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;