This is an automated email from the ASF dual-hosted git repository. janc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
The following commit(s) were added to refs/heads/master by this push: new 04fea982 nimble/host: Fix legacy advertising API with EXT_ADV enabled 04fea982 is described below commit 04fea98258cc814ca826e9f0fdacd1c5fb9d3965 Author: Szymon Janc <szymon.j...@codecoup.pl> AuthorDate: Wed May 8 11:58:21 2024 +0200 nimble/host: Fix legacy advertising API with EXT_ADV enabled Configured advertisign instance is required in order to set advertising data when extended advertising HCI is used. Since when legacy PDU are in use we can set both AD and SCAN_RSP we can easily pre-configure selected instance just for this purpose and re-configure it before starting advertising without affecting set AD/SCAN_RSP. --- nimble/host/src/ble_gap.c | 60 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 733d6f1f..38da7120 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -202,6 +202,10 @@ struct ble_gap_slave_state { static bssnz_t struct ble_gap_slave_state ble_gap_slave[BLE_ADV_INSTANCES]; +#if MYNEWT_VAL(BLE_EXT_ADV) +static bool ext_adv_legacy_configured = false; +#endif + struct ble_gap_update_entry { SLIST_ENTRY(ble_gap_update_entry) next; struct ble_gap_upd_params params; @@ -1471,6 +1475,8 @@ ble_gap_reset_state(int reason) ble_gap_adv_finished(i, reason, 0, 0); } } + + ext_adv_legacy_configured = false; #else if (ble_gap_adv_active_instance(0)) { /* Indicate to application that advertising has stopped. */ @@ -2552,7 +2558,13 @@ ble_gap_adv_stop(void) return rc; } - return ble_gap_ext_adv_remove(MYNEWT_VAL(BLE_HS_EXT_ADV_LEGACY_INSTANCE)); + rc = ble_gap_ext_adv_remove(MYNEWT_VAL(BLE_HS_EXT_ADV_LEGACY_INSTANCE)); + if (rc) { + return rc; + } + + ext_adv_legacy_configured = false; + return 0; #else int rc; @@ -2804,13 +2816,15 @@ ble_gap_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr, ext_params.filter_policy = adv_params->filter_policy; ext_params.high_duty_directed = adv_params->high_duty_cycle; - /* configure instance 0 */ + /* configure legacy instance */ rc = ble_gap_ext_adv_configure(MYNEWT_VAL(BLE_HS_EXT_ADV_LEGACY_INSTANCE), &ext_params, NULL, cb, cb_arg); if (rc) { return rc; } + ext_adv_legacy_configured = true; + if (duration_ms == BLE_HS_FOREVER) { duration = 0; } else { @@ -2900,6 +2914,38 @@ done: #endif } +#if MYNEWT_VAL(BLE_EXT_ADV) +static int +ble_gap_ext_adv_legacy_preconfigure(void) +{ + struct ble_gap_ext_adv_params ext_params; + int rc; + + if (ext_adv_legacy_configured) { + return 0; + } + + memset(&ext_params, 0, sizeof(ext_params)); + ext_params.own_addr_type = BLE_ADDR_RANDOM; + ext_params.primary_phy = BLE_HCI_LE_PHY_1M; + ext_params.secondary_phy = BLE_HCI_LE_PHY_1M; + ext_params.tx_power = 127; + ext_params.sid = 0; + ext_params.legacy_pdu = 1; + ext_params.scannable = 1; + ext_params.connectable = 1; + + rc = ble_gap_ext_adv_configure(MYNEWT_VAL(BLE_HS_EXT_ADV_LEGACY_INSTANCE), + &ext_params, NULL, NULL, NULL); + if (rc) { + return rc; + } + + ext_adv_legacy_configured = true; + return 0; +} +#endif + int ble_gap_adv_set_data(const uint8_t *data, int data_len) { @@ -2913,6 +2959,11 @@ ble_gap_adv_set_data(const uint8_t *data, int data_len) return BLE_HS_EINVAL; } + rc = ble_gap_ext_adv_legacy_preconfigure(); + if (rc) { + return rc; + } + mbuf = os_msys_get_pkthdr(data_len, 0); if (!mbuf) { return BLE_HS_ENOMEM; @@ -2966,6 +3017,11 @@ ble_gap_adv_rsp_set_data(const uint8_t *data, int data_len) return BLE_HS_EINVAL; } + rc = ble_gap_ext_adv_legacy_preconfigure(); + if (rc) { + return rc; + } + mbuf = os_msys_get_pkthdr(data_len, 0); if (!mbuf) { return BLE_HS_ENOMEM;