Bluetooth: controller: Add Read Static Addresses VS command

Implement the first Vendor-Specific Command of the Zephyr specification
other than the 3 mandatory ones already present in the codebase, along
with a Kconfig option to enable and disable the presence of the VS
commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
Carles Cufi 2017-08-16 12:59:05 +02:00 committed by Anas Nashif
commit b7a5fab4cf
5 changed files with 61 additions and 0 deletions

View file

@ -30,6 +30,13 @@ endchoice
comment "BLE Controller configuration"
config BT_CTLR_HCI_VS_EXT
bool "Zephyr HCI Vendor-Specific Extensions"
default y
help
Enable support for the Zephyr HCI Vendor-Specific Extensions in the
Controller.
config BT_CTLR_DUP_FILTER_LEN
prompt "Number of addresses in the scan duplicate filter"
int

View file

@ -1577,6 +1577,10 @@ static void vs_read_supported_commands(struct net_buf *buf,
/* Set Version Information, Supported Commands, Supported Features. */
rp->commands[0] |= BIT(0) | BIT(1) | BIT(2);
#if defined(CONFIG_BT_CTLR_HCI_VS_EXT)
/* Read Static Addresses */
rp->commands[1] |= BIT(0);
#endif /* CONFIG_BT_CTLR_HCI_VS_EXT */
}
static void vs_read_supported_features(struct net_buf *buf,
@ -1590,6 +1594,47 @@ static void vs_read_supported_features(struct net_buf *buf,
memset(&rp->features[0], 0x00, sizeof(rp->features));
}
#if defined(CONFIG_BT_CTLR_HCI_VS_EXT)
static void vs_read_static_addrs(struct net_buf *buf, struct net_buf **evt)
{
struct bt_hci_rp_vs_read_static_addrs *rp;
#if defined(CONFIG_SOC_FAMILY_NRF5)
/* Read address from nRF5-specific storage
* Non-initialized FICR values default to 0xFF, skip if no address
* present. Also if a public address lives in FICR, do not use in this
* function.
*/
if (((NRF_FICR->DEVICEADDR[0] != UINT32_MAX) ||
((NRF_FICR->DEVICEADDR[1] & UINT16_MAX) != UINT16_MAX)) &&
(NRF_FICR->DEVICEADDRTYPE & 0x01)) {
struct bt_hci_vs_static_addr *addr;
rp = cmd_complete(evt, sizeof(*rp) + sizeof(*addr));
rp->num_addrs = 1;
addr = &rp->a[0];
sys_put_le32(NRF_FICR->DEVICEADDR[0], &addr->bdaddr.val[0]);
sys_put_le16(NRF_FICR->DEVICEADDR[1], &addr->bdaddr.val[4]);
/* The FICR value is a just a random number, with no knowledge
* of the Bluetooth Specification requirements for random
* static addresses.
*/
BT_ADDR_SET_STATIC(&addr->bdaddr);
/* Mark IR as invalid */
memset(addr->ir, 0x00, sizeof(addr->ir));
return;
}
#endif /* CONFIG_SOC_FAMILY_NRF5 */
rp = cmd_complete(evt, sizeof(*rp));
rp->status = 0x00;
rp->num_addrs = 0;
}
#endif /* CONFIG_BT_CTLR_HCI_VS_EXT */
static int vendor_cmd_handle(u16_t ocf, struct net_buf *cmd,
struct net_buf **evt)
{
@ -1606,6 +1651,12 @@ static int vendor_cmd_handle(u16_t ocf, struct net_buf *cmd,
vs_read_supported_features(cmd, evt);
break;
#if defined(CONFIG_BT_CTLR_HCI_VS_EXT)
case BT_OCF(BT_HCI_OP_VS_READ_STATIC_ADDRS):
vs_read_static_addrs(cmd, evt);
break;
#endif /* CONFIG_BT_CTLR_HCI_VS_EXT */
default:
return -EINVAL;
}

View file

@ -1,5 +1,6 @@
CONFIG_BT=y
CONFIG_BT_CTLR=y
CONFIG_BT_CTLR_HCI_VS_EXT=n
CONFIG_BT_CTLR_WORKER_PRIO=0
CONFIG_BT_CTLR_JOB_PRIO=0
CONFIG_BT_CTLR_XTAL_ADVANCED=y

View file

@ -1,5 +1,6 @@
CONFIG_BT=y
CONFIG_BT_CTLR=y
CONFIG_BT_CTLR_HCI_VS_EXT=y
CONFIG_BT_CTLR_WORKER_PRIO=0
CONFIG_BT_CTLR_JOB_PRIO=1
CONFIG_BT_CTLR_XTAL_ADVANCED=n

View file

@ -1,5 +1,6 @@
CONFIG_BT=y
CONFIG_BT_CTLR=y
CONFIG_BT_CTLR_HCI_VS_EXT=n
CONFIG_BT_CTLR_WORKER_PRIO=0
CONFIG_BT_CTLR_JOB_PRIO=0
CONFIG_BT_CTLR_XTAL_ADVANCED=n