diff --git a/samples/bluetooth/central_hr/overlay-extended.conf b/samples/bluetooth/central_hr/overlay-extended.conf new file mode 100644 index 0000000000..54f501f400 --- /dev/null +++ b/samples/bluetooth/central_hr/overlay-extended.conf @@ -0,0 +1,6 @@ +CONFIG_BT_EXT_ADV=y + +# Increase Scan Data Length, as Complete Local Name is placed in the +# AUX_ADV_IND PDU compared to when it is placed in ADV_SCAN_IND PDU in the case +# of legacy advertising. +CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=36 diff --git a/samples/bluetooth/central_hr/overlay-phy_coded.conf b/samples/bluetooth/central_hr/overlay-phy_coded.conf new file mode 100644 index 0000000000..17d46e52ed --- /dev/null +++ b/samples/bluetooth/central_hr/overlay-phy_coded.conf @@ -0,0 +1,12 @@ +CONFIG_BT_EXT_ADV=y + +# Enable Coded PHY support +CONFIG_BT_CTLR_PHY_CODED=y + +# Disable auto PHY update, to switch to 2M PHY +CONFIG_BT_AUTO_PHY_UPDATE=n + +# Increase Scan Data Length, as Complete Local Name is placed in the +# AUX_ADV_IND PDU compared to when it is placed in ADV_SCAN_IND PDU in the case +# of legacy advertising. +CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=36 diff --git a/samples/bluetooth/central_hr/sample.yaml b/samples/bluetooth/central_hr/sample.yaml index 8dabb7121b..8a53401860 100644 --- a/samples/bluetooth/central_hr/sample.yaml +++ b/samples/bluetooth/central_hr/sample.yaml @@ -5,3 +5,35 @@ tests: arch_allow: x86 harness: bluetooth tags: bluetooth + sample.bluetooth.central_hr.bt_ll_sw_split.extended: + harness: bluetooth + platform_allow: + - nrf52_bsim + - nrf5340bsim/nrf5340/cpuapp + - nrf52dk/nrf52832 + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + integration_platforms: + - nrf52_bsim + - nrf5340bsim/nrf5340/cpuapp + - nrf52dk/nrf52832 + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + extra_args: EXTRA_CONF_FILE=overlay-extended.conf + tags: bluetooth + sample.bluetooth.central_hr.bt_ll_sw_split.phy_coded: + harness: bluetooth + platform_allow: + - nrf52_bsim + - nrf5340bsim/nrf5340/cpuapp + - nrf52dk/nrf52832 + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + integration_platforms: + - nrf52_bsim + - nrf5340bsim/nrf5340/cpuapp + - nrf52dk/nrf52832 + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + extra_args: EXTRA_CONF_FILE=overlay-phy_coded.conf + tags: bluetooth diff --git a/samples/bluetooth/central_hr/src/main.c b/samples/bluetooth/central_hr/src/main.c index 305066bccd..e1f07e1eb0 100644 --- a/samples/bluetooth/central_hr/src/main.c +++ b/samples/bluetooth/central_hr/src/main.c @@ -112,6 +112,7 @@ static bool eir_found(struct bt_data *data, void *user_data) } for (i = 0; i < data->data_len; i += sizeof(uint16_t)) { + struct bt_conn_le_create_param *create_param; struct bt_le_conn_param *param; const struct bt_uuid *uuid; uint16_t u16; @@ -129,12 +130,24 @@ static bool eir_found(struct bt_data *data, void *user_data) continue; } + printk("Creating connection with Coded PHY support\n"); param = BT_LE_CONN_PARAM_DEFAULT; - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - param, &default_conn); + create_param = BT_CONN_LE_CREATE_CONN; + create_param->options |= BT_CONN_LE_OPT_CODED; + err = bt_conn_le_create(addr, create_param, param, + &default_conn); if (err) { - printk("Create conn failed (err %d)\n", err); - start_scan(); + printk("Create connection with Coded PHY support failed (err %d)\n", + err); + + printk("Creating non-Coded PHY connection\n"); + create_param->options &= ~BT_CONN_LE_OPT_CODED; + err = bt_conn_le_create(addr, create_param, + param, &default_conn); + if (err) { + printk("Create connection failed (err %d)\n", err); + start_scan(); + } } return false; @@ -153,9 +166,12 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, printk("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i\n", dev, type, ad->len, rssi); - /* We're only interested in connectable events */ + /* We're only interested in legacy connectable events or + * possible extended advertising that are connectable. + */ if (type == BT_GAP_ADV_TYPE_ADV_IND || - type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND) { + type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND || + type == BT_GAP_ADV_TYPE_EXT_ADV) { bt_data_parse(ad, eir_found, (void *)addr); } } @@ -168,15 +184,22 @@ static void start_scan(void) * devices that might update their advertising data at runtime. */ struct bt_le_scan_param scan_param = { .type = BT_LE_SCAN_TYPE_ACTIVE, - .options = BT_LE_SCAN_OPT_NONE, + .options = BT_LE_SCAN_OPT_CODED, .interval = BT_GAP_SCAN_FAST_INTERVAL, .window = BT_GAP_SCAN_FAST_WINDOW, }; err = bt_le_scan_start(&scan_param, device_found); if (err) { - printk("Scanning failed to start (err %d)\n", err); - return; + printk("Scanning with Coded PHY support failed (err %d)\n", err); + + printk("Scanning without Coded PHY\n"); + scan_param.options &= ~BT_LE_SCAN_OPT_CODED; + err = bt_le_scan_start(&scan_param, device_found); + if (err) { + printk("Scanning failed to start (err %d)\n", err); + return; + } } printk("Scanning successfully started\n");