diff --git a/nimble/controller/include/controller/ble_ll_scan.h b/nimble/controller/include/controller/ble_ll_scan.h index 07e4c9208a..f30e614dbc 100644 --- a/nimble/controller/include/controller/ble_ll_scan.h +++ b/nimble/controller/include/controller/ble_ll_scan.h @@ -156,6 +156,10 @@ struct ble_ll_scan_sm /* Connection sm for initiator scan */ struct ble_ll_conn_sm *connsm; #endif + +#if MYNEWT_VAL(BLE_LL_HCI_VS_SET_SCAN_CFG) + uint32_t vs_flags; +#endif }; /* Scan types */ @@ -259,6 +263,10 @@ ble_ll_scan_rx_filter(uint8_t own_addr_type, uint8_t scan_filt_policy, struct ble_ll_scan_addr_data *addrd, uint8_t *scan_ok); int ble_ll_scan_rx_check_init(struct ble_ll_scan_addr_data *addrd); +#if MYNEWT_VAL(BLE_LL_HCI_VS_SET_SCAN_CFG) +int ble_ll_scan_set_vs_flags(uint32_t flags); +#endif + #ifdef __cplusplus } #endif diff --git a/nimble/controller/src/ble_ll_hci_vs.c b/nimble/controller/src/ble_ll_hci_vs.c index 1710e456fe..ea0a042dec 100644 --- a/nimble/controller/src/ble_ll_hci_vs.c +++ b/nimble/controller/src/ble_ll_hci_vs.c @@ -356,6 +356,33 @@ ble_ll_hci_vs_set_local_irk(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen, } #endif +#if MYNEWT_VAL(BLE_LL_HCI_VS_SET_SCAN_CFG) +static int +ble_ll_hci_vs_set_scan_cfg(uint16_t ocf, const uint8_t *cmdbuf, uint8_t cmdlen, + uint8_t *rspbuf, uint8_t *rsplen) +{ + const struct ble_hci_vs_set_scan_cfg_cp *cmd = (const void *)cmdbuf; + int rc; + + if (cmdlen != sizeof(*cmd)) { + return BLE_ERR_INV_HCI_CMD_PARMS; + } + + if (cmd->flags > BLE_HCI_OCF_VS_SET_SCAN_CFG_NO_EXT) { + return BLE_ERR_INV_HCI_CMD_PARMS; + } + + rc = ble_ll_scan_set_vs_flags(cmd->flags); + if (rc != 0) { + return BLE_ERR_CMD_DISALLOWED; + } + + *rsplen = 0; + + return 0; +} +#endif + static struct ble_ll_hci_vs_cmd g_ble_ll_hci_vs_cmds[] = { BLE_LL_HCI_VS_CMD(BLE_HCI_OCF_VS_RD_STATIC_ADDR, ble_ll_hci_vs_rd_static_addr), @@ -386,6 +413,10 @@ static struct ble_ll_hci_vs_cmd g_ble_ll_hci_vs_cmds[] = { BLE_LL_HCI_VS_CMD(BLE_HCI_OCF_VS_SET_LOCAL_IRK, ble_ll_hci_vs_set_local_irk), #endif +#if MYNEWT_VAL(BLE_LL_HCI_VS_SET_SCAN_CFG) + BLE_LL_HCI_VS_CMD(BLE_HCI_OCF_VS_SET_SCAN_CFG, + ble_ll_hci_vs_set_scan_cfg) +#endif }; static struct ble_ll_hci_vs_cmd * diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index 670f6b38cb..273afc1a26 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -2023,6 +2023,20 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd return; } +#if MYNEWT_VAL(BLE_LL_HCI_VS_SET_SCAN_CFG) + if ((ptype == BLE_ADV_PDU_TYPE_ADV_EXT_IND) && + (scansm->vs_flags & BLE_HCI_OCF_VS_SET_SCAN_CFG_NO_EXT)) { + ble_ll_scan_chk_resume(); + return; + } + + if ((ptype != BLE_ADV_PDU_TYPE_ADV_EXT_IND) && + (scansm->vs_flags & BLE_HCI_OCF_VS_SET_SCAN_CFG_NO_LEGACY)) { + ble_ll_scan_chk_resume(); + return; + } +#endif + #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) if (ptype == BLE_ADV_PDU_TYPE_ADV_EXT_IND) { ble_ll_scan_aux_pkt_in_on_ext(om, hdr); @@ -2258,6 +2272,24 @@ ble_ll_scan_hci_set_ext_params(const uint8_t *cmdbuf, uint8_t len) #endif +#if MYNEWT_VAL(BLE_LL_HCI_VS_SET_SCAN_CFG) +int +ble_ll_scan_set_vs_flags(uint32_t flags) +{ + struct ble_ll_scan_sm *scansm; + + scansm = &g_ble_ll_scan_sm; + + if (scansm->scan_enabled || scansm->connsm) { + return 1; + } + + scansm->vs_flags = flags; + + return 0; +} +#endif + #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) static void ble_ll_scan_duration_period_timers_restart(struct ble_ll_scan_sm *scansm) diff --git a/nimble/controller/syscfg.yml b/nimble/controller/syscfg.yml index 862a36a523..531cfbe926 100644 --- a/nimble/controller/syscfg.yml +++ b/nimble/controller/syscfg.yml @@ -422,6 +422,14 @@ syscfg.defs: value: 0 restrictions: - BLE_LL_HCI_VS if 1 + BLE_LL_HCI_VS_SET_SCAN_CFG: + description: > + Enables HCI command to set global PDU filter for scanner. + It allows to ignore extended or legacy PDUs while scanning. + value: 0 + restrictions: + - BLE_LL_HCI_VS if 1 + - BLE_LL_CFG_FEAT_LL_EXT_ADV if 1 BLE_LL_HCI_VS_EVENT_ON_ASSERT: diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 252b033973..2f68cdaa2e 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1396,6 +1396,14 @@ struct ble_hci_vs_set_local_irk_cp { uint8_t irk[16]; } __attribute__((packed)); +#define BLE_HCI_OCF_VS_SET_SCAN_CFG_NO_LEGACY 0x00000001 +#define BLE_HCI_OCF_VS_SET_SCAN_CFG_NO_EXT 0x00000002 + +#define BLE_HCI_OCF_VS_SET_SCAN_CFG (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x000B)) +struct ble_hci_vs_set_scan_cfg_cp { + uint32_t flags; +} __attribute__((packed)); + /* Command Specific Definitions */ /* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */ #define BLE_HCI_CTLR_TO_HOST_FC_OFF (0)