diff --git a/include/zephyr/bluetooth/bluetooth.h b/include/zephyr/bluetooth/bluetooth.h index c93cf4a5f25f990..c51a87ae0f12da9 100644 --- a/include/zephyr/bluetooth/bluetooth.h +++ b/include/zephyr/bluetooth/bluetooth.h @@ -1075,6 +1075,22 @@ int bt_le_adv_start(const struct bt_le_adv_param *param, const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len); +#if !defined(CONFIG_BT_EXT_ADV) && defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) +/** + * @brief Add legacy advertising debug callbacks + * + * Set callback structure to legacy advertisement . This feature is meant for + * manufacturing, for a possible method for updating firmware, and for debugging. + * + * @param cb Callback struct to notify about advertiser activity. Can be NULL. + * + * @return Zero on success or (negative) error code otherwise. + * @return -ENOMEM No free connection objects available for connectable + * advertiser. + */ +int bt_le_adv_debug_cb(const struct bt_le_ext_adv_cb *cb); +#endif /* !defined(CONFIG_BT_EXT_ADV) && defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) */ + /** * @brief Update advertising * diff --git a/include/zephyr/bluetooth/hci_vs.h b/include/zephyr/bluetooth/hci_vs.h index aea92846e56267a..8ebd33194fc8e39 100644 --- a/include/zephyr/bluetooth/hci_vs.h +++ b/include/zephyr/bluetooth/hci_vs.h @@ -52,7 +52,7 @@ extern "C" { #define BT_HCI_VS_FW_VAR_VS_CTLR 0x0002 #define BT_HCI_VS_FW_VAR_FW_LOADER 0x0003 #define BT_HCI_VS_FW_VAR_RESCUE_IMG 0x0004 -#define BT_HCI_OP_VS_READ_VERSION_INFO BT_OP(BT_OGF_VS, 0x0001) +#define BT_HCI_OP_VS_READ_VERSION_INFO BT_OP(BT_OGF_VS, 0x0001) struct bt_hci_rp_vs_read_version_info { uint8_t status; uint16_t hw_platform; @@ -63,13 +63,13 @@ struct bt_hci_rp_vs_read_version_info { uint32_t fw_build; } __packed; -#define BT_HCI_OP_VS_READ_SUPPORTED_COMMANDS BT_OP(BT_OGF_VS, 0x0002) +#define BT_HCI_OP_VS_READ_SUPPORTED_COMMANDS BT_OP(BT_OGF_VS, 0x0002) struct bt_hci_rp_vs_read_supported_commands { uint8_t status; uint8_t commands[64]; } __packed; -#define BT_HCI_OP_VS_READ_SUPPORTED_FEATURES BT_OP(BT_OGF_VS, 0x0003) +#define BT_HCI_OP_VS_READ_SUPPORTED_FEATURES BT_OP(BT_OGF_VS, 0x0003) struct bt_hci_rp_vs_read_supported_features { uint8_t status; uint8_t features[8]; @@ -155,9 +155,9 @@ struct bt_hci_cp_vs_set_scan_req_reports { uint8_t enable; } __packed; -#define BT_HCI_VS_LL_HANDLE_TYPE_ADV 0x00 -#define BT_HCI_VS_LL_HANDLE_TYPE_SCAN 0x01 -#define BT_HCI_VS_LL_HANDLE_TYPE_CONN 0x02 +#define BT_HCI_VS_LL_HANDLE_TYPE_ADV 0x00 +#define BT_HCI_VS_LL_HANDLE_TYPE_SCAN 0x01 +#define BT_HCI_VS_LL_HANDLE_TYPE_CONN 0x02 #define BT_HCI_VS_LL_TX_POWER_LEVEL_NO_PREF 0x7F #define BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL BT_OP(BT_OGF_VS, 0x000e) struct bt_hci_cp_vs_write_tx_power_level { @@ -194,16 +194,16 @@ struct bt_hci_rp_vs_read_usb_transport_mode { uint8_t supported_mode[0]; } __packed; -#define BT_HCI_VS_USB_H2_MODE 0x00 -#define BT_HCI_VS_USB_H4_MODE 0x01 +#define BT_HCI_VS_USB_H2_MODE 0x00 +#define BT_HCI_VS_USB_H4_MODE 0x01 -#define BT_HCI_OP_VS_SET_USB_TRANSPORT_MODE BT_OP(BT_OGF_VS, 0x0011) +#define BT_HCI_OP_VS_SET_USB_TRANSPORT_MODE BT_OP(BT_OGF_VS, 0x0011) struct bt_hci_cp_vs_set_usb_transport_mode { uint8_t mode; } __packed; -#define BT_HCI_OP_VS_SET_MIN_NUM_USED_CHANS BT_OP(BT_OGF_VS, 0x0012) +#define BT_HCI_OP_VS_SET_MIN_NUM_USED_CHANS BT_OP(BT_OGF_VS, 0x0012) struct bt_hci_cp_vs_set_min_num_used_chans { uint16_t handle; @@ -211,6 +211,12 @@ struct bt_hci_cp_vs_set_min_num_used_chans { uint8_t min_used_chans; } __packed; +#define BT_HCI_OP_VS_SET_SCAN_REQ_RCVD_MASK BT_OP(BT_OGF_VS, 0x0013) + +struct bt_hci_cp_vs_set_scan_req_rcvd_mask { + uint8_t enable; +} __packed; + /* Events */ struct bt_hci_evt_vs { diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 2fd7dc41a9ebe5d..01ff050ba6ccc3a 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -4951,6 +4951,20 @@ static void vs_read_tx_power_level(struct net_buf *buf, struct net_buf **evt) } #endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ +#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) +static void vs_set_scan_req_rcvd_mask(struct net_buf *buf, struct net_buf **evt) +{ + struct bt_hci_cp_vs_set_scan_req_rcvd_mask *cmd = (void *)buf->data; + + if (cmd->enable != 0) { + le_event_mask |= BT_EVT_MASK_LE_SCAN_REQ_RECEIVED; + } else { + le_event_mask &= ~BT_EVT_MASK_LE_SCAN_REQ_RECEIVED; + } + *evt = cmd_complete_status(0x00); +} +#endif /* CONFIG_BT_CTLR_SCAN_REQ_NOTIFY */ + #if defined(CONFIG_BT_HCI_VS_FATAL_ERROR) /* A memory pool for vandor specific events for fatal error reporting purposes. */ NET_BUF_POOL_FIXED_DEFINE(vs_err_tx_pool, 1, BT_BUF_EVT_RX_SIZE, @@ -5493,6 +5507,12 @@ int hci_vendor_cmd_handle_common(uint16_t ocf, struct net_buf *cmd, break; #endif /* CONFIG_BT_HCI_MESH_EXT */ +#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) + case BT_OCF(BT_HCI_OP_VS_SET_SCAN_REQ_RCVD_MASK): + vs_set_scan_req_rcvd_mask(cmd, evt); + break; +#endif /* CONFIG_BT_CTLR_SCAN_REQ_NOTIFY */ + default: return -EINVAL; } diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index b5595e5e9c25d4b..244719dd45f3845 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -340,7 +340,7 @@ uint8_t ll_adv_params_set(uint16_t interval, uint8_t adv_type, adv->lll.chan_map = chan_map; adv->lll.filter_policy = filter_policy; -#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) +#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) && defined(CONFIG_BT_CTLR_ADV_EXT) adv->lll.scan_req_notify = sreq; #endif diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 7134e6fa89a43fc..e274dba08ab25c1 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -1381,6 +1381,21 @@ int bt_le_adv_start(const struct bt_le_adv_param *param, return err; } +#if !defined(CONFIG_BT_EXT_ADV) && defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) +int bt_le_adv_debug_cb(const struct bt_le_ext_adv_cb *cb) +{ + struct bt_le_ext_adv *adv = adv_get_legacy(); + + if (!adv) { + return -ENOMEM; + } + + adv->cb = cb; + + return 0; +} +#endif /* !defined(CONFIG_BT_EXT_ADV) && defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) */ + int bt_le_adv_stop(void) { struct bt_le_ext_adv *adv = bt_le_adv_lookup_legacy(); @@ -2250,14 +2265,22 @@ void bt_hci_le_adv_set_terminated(struct net_buf *buf) } } } +#endif /* defined(CONFIG_BT_BROADCASTER) */ +#endif /* defined(CONFIG_BT_EXT_ADV) */ +#if defined(CONFIG_BT_EXT_ADV) || defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) +#if defined(CONFIG_BT_BROADCASTER) void bt_hci_le_scan_req_received(struct net_buf *buf) { struct bt_hci_evt_le_scan_req_received *evt; struct bt_le_ext_adv *adv; evt = (void *)buf->data; +#if defined(CONFIG_BT_EXT_ADV) adv = bt_adv_lookup_handle(evt->handle); +#else + adv = adv_get_legacy(); +#endif LOG_DBG("handle %u peer %s", evt->handle, bt_addr_le_str(&evt->addr)); @@ -2282,4 +2305,4 @@ void bt_hci_le_scan_req_received(struct net_buf *buf) } } #endif /* defined(CONFIG_BT_BROADCASTER) */ -#endif /* defined(CONFIG_BT_EXT_ADV) */ +#endif /* defined(CONFIG_BT_EXT_ADV) || defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) */ diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 2f54298b41be621..b2701be9f98c128 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -2534,6 +2534,12 @@ static const struct event_handler meta_events[] = { #endif /* CONFIG_BT_CONN */ #endif /* defined(CONFIG_BT_PER_ADV_SYNC) */ #endif /* defined(CONFIG_BT_EXT_ADV) */ +#if defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) +#if defined(CONFIG_BT_BROADCASTER) + EVENT_HANDLER(BT_HCI_EVT_LE_SCAN_REQ_RECEIVED, bt_hci_le_scan_req_received, + sizeof(struct bt_hci_evt_le_scan_req_received)), +#endif +#endif /* defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) */ #if defined(CONFIG_BT_ISO_UNICAST) EVENT_HANDLER(BT_HCI_EVT_LE_CIS_ESTABLISHED, hci_le_cis_established, sizeof(struct bt_hci_evt_le_cis_established)), diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index ce4fc5a9b63e923..f065fd80ff6f195 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -148,7 +148,7 @@ struct bt_le_ext_adv { ATOMIC_DEFINE(flags, BT_ADV_NUM_FLAGS); -#if defined(CONFIG_BT_EXT_ADV) +#if defined(CONFIG_BT_EXT_ADV) || defined(CONFIG_BT_CTLR_SCAN_REQ_NOTIFY) const struct bt_le_ext_adv_cb *cb; /* TX Power in use by the controller */