diff --git a/subsys/bluetooth/controller/ll_sw/ll_adv.c b/subsys/bluetooth/controller/ll_sw/ll_adv.c index eefcf64326f..09d2df27dc1 100644 --- a/subsys/bluetooth/controller/ll_sw/ll_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ll_adv.c @@ -411,12 +411,6 @@ u8_t ll_adv_enable(u8_t enable) pdu_adv = (struct pdu_adv *)&radio_adv_data->data [radio_adv_data->last][0]; - if (pdu_adv->tx_addr) { - if (!mem_nz(ll_addr_get(1, NULL), BDADDR_SIZE)) { - return BT_HCI_ERR_INVALID_PARAM; - } - } - radio_scan_data = radio_scan_data_get(); pdu_scan = (struct pdu_adv *)&radio_scan_data->data [radio_scan_data->last][0]; @@ -435,8 +429,14 @@ u8_t ll_adv_enable(u8_t enable) /* AdvA, fill here at enable */ if (h->adv_addr) { - memcpy(ptr, ll_addr_get(pdu_adv->tx_addr, NULL), - BDADDR_SIZE); + u8_t *tx_addr = ll_addr_get(pdu_adv->tx_addr, NULL); + + /* TODO: Privacy check */ + if (pdu_adv->tx_addr && !mem_nz(tx_addr, BDADDR_SIZE)) { + return BT_HCI_ERR_INVALID_PARAM; + } + + memcpy(ptr, tx_addr, BDADDR_SIZE); } /* TODO: TargetA, fill here at enable */ @@ -460,9 +460,11 @@ u8_t ll_adv_enable(u8_t enable) ll_rl_pdu_adv_update(rl_idx, pdu_adv); ll_rl_pdu_adv_update(rl_idx, pdu_scan); + priv = true; } #endif /* !CONFIG_BT_CTLR_PRIVACY */ + if (!priv) { memcpy(&pdu_adv->adv_ind.addr[0], ll_addr_get(pdu_adv->tx_addr, NULL), @@ -471,6 +473,15 @@ u8_t ll_adv_enable(u8_t enable) ll_addr_get(pdu_adv->tx_addr, NULL), BDADDR_SIZE); } + + /* In case the local IRK was not set or no match was + * found the fallback address was used instead, check + * that a valid address has been set. + */ + if ((priv || pdu_adv->tx_addr) && + !mem_nz(&pdu_adv->adv_ind.addr[0], BDADDR_SIZE)) { + return BT_HCI_ERR_INVALID_PARAM; + } } #if defined(CONFIG_BT_HCI_MESH_EXT)