Skip to content

Commit

Permalink
nimble/ll: Add vs hci cmd with additional scan cfg
Browse files Browse the repository at this point in the history
This allows to configure scanner to ignore either
legacy or extended packets. If scan is enabled
command returns command disallowed error.
  • Loading branch information
m-gorecki committed Nov 18, 2024
1 parent ca67e30 commit 41235f8
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nimble/controller/include/controller/ble_ll_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions nimble/controller/src/ble_ll_hci_vs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 *
Expand Down
32 changes: 32 additions & 0 deletions nimble/controller/src/ble_ll_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions nimble/controller/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions nimble/include/nimble/hci_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 41235f8

Please sign in to comment.