This is an automated email from the ASF dual-hosted git repository. mgorecki pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 77902be94314fb6de8707de40083a3087feb8e77 Author: Michal Gorecki <[email protected]> AuthorDate: Mon Sep 16 12:32:50 2024 +0200 nimble/ll: Refactor DID update Now we can universally update DID with the same function, also for periodic advertising. --- nimble/controller/src/ble_ll_adv.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c index 056df4f60..b50422517 100644 --- a/nimble/controller/src/ble_ll_adv.c +++ b/nimble/controller/src/ble_ll_adv.c @@ -1931,10 +1931,10 @@ ble_ll_adv_set_adv_params(const uint8_t *cmdbuf, uint8_t len) } #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) -static void -ble_ll_adv_update_did(struct ble_ll_adv_sm *advsm) +static uint16_t +ble_ll_adv_update_did(uint16_t old_adi) { - uint16_t old_adi = advsm->adi; + uint16_t new_adi; /* * The Advertising DID for a given advertising set shall be initialized @@ -1945,8 +1945,10 @@ ble_ll_adv_update_did(struct ble_ll_adv_sm *advsm) * the previously used value. */ do { - advsm->adi = (advsm->adi & 0xf000) | (ble_ll_rand() & 0x0fff); - } while (old_adi == advsm->adi); + new_adi = (old_adi & 0xf000) | (ble_ll_rand() & 0x0fff); + } while (old_adi == new_adi); + + return new_adi; } #endif @@ -1980,7 +1982,7 @@ ble_ll_adv_update_adv_scan_rsp_data(struct ble_ll_adv_sm *advsm) #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) /* DID shall be updated when host provides new advertising data */ - ble_ll_adv_update_did(advsm); + advsm->adi = ble_ll_adv_update_did(advsm->adi); #endif } @@ -2675,7 +2677,7 @@ ble_ll_adv_sm_start_periodic(struct ble_ll_adv_sm *advsm) * advertisers should update the Advertising DID when a periodic advertising * train is enabled. */ - ble_ll_adv_update_did(advsm); + advsm->adi = ble_ll_adv_update_did(advsm->adi); advsm->periodic_adv_active = 1; @@ -2718,7 +2720,7 @@ ble_ll_adv_sm_stop_periodic(struct ble_ll_adv_sm *advsm) * advertisers should update the Advertising DID when a periodic advertising * train is disabled. */ - ble_ll_adv_update_did(advsm); + advsm->adi = ble_ll_adv_update_did(advsm->adi); /* Remove any scheduled advertising items */ advsm->periodic_adv_active = 0; @@ -3140,7 +3142,7 @@ ble_ll_adv_set_scan_rsp_data(const uint8_t *data, uint8_t datalen, } /* DID shall be updated when host provides new scan response data */ - ble_ll_adv_update_did(advsm); + advsm->adi = ble_ll_adv_update_did(advsm->adi); #endif } @@ -3215,7 +3217,7 @@ ble_ll_adv_set_adv_data(const uint8_t *data, uint8_t datalen, uint8_t instance, } /* update DID only */ - ble_ll_adv_update_did(advsm); + advsm->adi = ble_ll_adv_update_did(advsm->adi); return BLE_ERR_SUCCESS; case BLE_HCI_LE_SET_DATA_OPER_LAST: ble_ll_adv_flags_clear(advsm, BLE_LL_ADV_SM_FLAG_ADV_DATA_INCOMPLETE); @@ -3303,7 +3305,7 @@ ble_ll_adv_set_adv_data(const uint8_t *data, uint8_t datalen, uint8_t instance, } /* DID shall be updated when host provides new advertising data */ - ble_ll_adv_update_did(advsm); + advsm->adi = ble_ll_adv_update_did(advsm->adi); #endif }
