From b380407c234735f49ade1c524575352f14a3d76e Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Fri, 22 Nov 2019 19:28:30 +0100 Subject: [PATCH 1/4] nimble/ll: Fix aux_data field names Let's make fields in aux_data names corresponds to names from spec, i.e. there is AdvA and TargetA there. --- .../include/controller/ble_ll_scan.h | 12 ++-- nimble/controller/src/ble_ll_scan.c | 70 +++++++++---------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/nimble/controller/include/controller/ble_ll_scan.h b/nimble/controller/include/controller/ble_ll_scan.h index 25d11e96d..faad1dc31 100644 --- a/nimble/controller/include/controller/ble_ll_scan.h +++ b/nimble/controller/include/controller/ble_ll_scan.h @@ -87,8 +87,8 @@ struct ble_ll_scan_params uint32_t scan_win_start_time; }; -#define BLE_LL_AUX_HAS_ADDRA 0x01 -#define BLE_LL_AUX_HAS_DIR_ADDRA 0x02 +#define BLE_LL_AUX_HAS_ADVA 0x01 +#define BLE_LL_AUX_HAS_TARGETA 0x02 #define BLE_LL_AUX_HAS_ADI 0x04 #define BLE_LL_AUX_FLAG_AUX_RECEIVED 0x01 @@ -124,10 +124,10 @@ struct ble_ll_aux_data { uint16_t adi; uint32_t offset; uint8_t offset_units; - uint8_t addr[6]; - uint8_t addr_type; - uint8_t dir_addr[6]; - uint8_t dir_addr_type; + uint8_t adva[6]; + uint8_t adva_type; + uint8_t targeta[6]; + uint8_t targeta_type; uint16_t evt_type; struct ble_ll_sched_item sch; struct ble_hci_ev *evt; diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index 4baa70b86..c5eefd805 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -472,14 +472,14 @@ ble_ll_scan_send_truncated(struct ble_ll_aux_data *aux_data) report->evt_type = aux_data->evt_type; report->evt_type |= BLE_HCI_ADV_DATA_STATUS_TRUNCATED; - if (aux_data->flags & BLE_LL_AUX_HAS_ADDRA) { - memcpy(report->addr, aux_data->addr, 6); - report->addr_type = aux_data->addr_type; + if (aux_data->flags & BLE_LL_AUX_HAS_ADVA) { + memcpy(report->addr, aux_data->adva, 6); + report->addr_type = aux_data->adva_type; } - if (aux_data->flags & BLE_LL_AUX_HAS_DIR_ADDRA) { - memcpy(report->dir_addr, aux_data->dir_addr, 6); - report->dir_addr_type = aux_data->dir_addr_type; + if (aux_data->flags & BLE_LL_AUX_HAS_TARGETA) { + memcpy(report->dir_addr, aux_data->targeta, 6); + report->dir_addr_type = aux_data->targeta_type; } report->sid = aux_data->adi >> 12; @@ -1858,9 +1858,9 @@ ble_ll_scan_update_aux_data(struct ble_mbuf_hdr *ble_hdr, uint8_t *rxbuf, /* Now parse extended header... */ if (eh_flags & (1 << BLE_LL_EXT_ADV_ADVA_BIT)) { - aux_data->flags |= BLE_LL_AUX_HAS_ADDRA; - memcpy(aux_data->addr, eh, 6); - aux_data->addr_type = !!(pdu_hdr & BLE_ADV_PDU_HDR_TXADD_MASK); + aux_data->flags |= BLE_LL_AUX_HAS_ADVA; + memcpy(aux_data->adva, eh, 6); + aux_data->adva_type = !!(pdu_hdr & BLE_ADV_PDU_HDR_TXADD_MASK); eh += BLE_LL_EXT_ADV_ADVA_SIZE; if (adva_present) { @@ -1869,9 +1869,9 @@ ble_ll_scan_update_aux_data(struct ble_mbuf_hdr *ble_hdr, uint8_t *rxbuf, } if (eh_flags & (1 << BLE_LL_EXT_ADV_TARGETA_BIT)) { - aux_data->flags |= BLE_LL_AUX_HAS_DIR_ADDRA; - memcpy(aux_data->dir_addr, eh, 6); - aux_data->dir_addr_type = !!(pdu_hdr & BLE_ADV_PDU_HDR_RXADD_MASK); + aux_data->flags |= BLE_LL_AUX_HAS_TARGETA; + memcpy(aux_data->targeta, eh, 6); + aux_data->targeta_type = !!(pdu_hdr & BLE_ADV_PDU_HDR_RXADD_MASK); eh += BLE_LL_EXT_ADV_TARGETA_SIZE; } @@ -2110,13 +2110,13 @@ done: if (aux_data) { /* If address has been provided, we do have it already in aux_data.*/ - if (aux_data->flags & BLE_LL_AUX_HAS_ADDRA) { + if (aux_data->flags & BLE_LL_AUX_HAS_ADVA) { if (!has_adva) { - *addr = aux_data->addr; - *addr_type = aux_data->addr_type; + *addr = aux_data->adva; + *addr_type = aux_data->adva_type; } else { - memcpy(aux_data->addr, *addr, 6); - aux_data->addr_type = *addr_type; + memcpy(aux_data->adva, *addr, 6); + aux_data->adva_type = *addr_type; } } @@ -2124,13 +2124,13 @@ done: return 0; } - if (aux_data->flags & BLE_LL_AUX_HAS_DIR_ADDRA) { + if (aux_data->flags & BLE_LL_AUX_HAS_TARGETA) { if (!has_inita) { - *inita = aux_data->dir_addr; - *inita_type = aux_data->dir_addr_type; + *inita = aux_data->targeta; + *inita_type = aux_data->targeta_type; } else { - memcpy(aux_data->dir_addr, *inita, 6); - aux_data->dir_addr_type = *inita_type; + memcpy(aux_data->targeta, *inita, 6); + aux_data->targeta_type = *inita_type; } } } @@ -2293,13 +2293,13 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) ext_adv_mode = rxbuf[2] >> 6; aux_data = ble_hdr->rxinfo.user_data; - if (aux_data->flags & BLE_LL_AUX_HAS_ADDRA) { - peer = aux_data->addr; - peer_addr_type = aux_data->addr_type; + if (aux_data->flags & BLE_LL_AUX_HAS_ADVA) { + peer = aux_data->adva; + peer_addr_type = aux_data->adva_type; } - if (aux_data->flags & BLE_LL_AUX_HAS_DIR_ADDRA) { - inita = aux_data->dir_addr; - inita_type = aux_data->dir_addr_type; + if (aux_data->flags & BLE_LL_AUX_HAS_TARGETA) { + inita = aux_data->targeta; + inita_type = aux_data->targeta_type; } rc = -1; @@ -2817,7 +2817,7 @@ done: if (rc == 0) { if (aux_data->evt_type & BLE_HCI_ADV_SCAN_RSP_MASK) { /* Complete scan response can be added to duplicates list */ - ble_ll_scan_add_scan_rsp_adv(aux_data->addr, aux_data->addr_type, + ble_ll_scan_add_scan_rsp_adv(aux_data->adva, aux_data->adva_type, 1, aux_data->adi); } else if (is_scannable_aux) { /* @@ -3113,13 +3113,13 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd if (aux_data) { ext_adv_mode = rxbuf[2] >> 6; - if (aux_data->flags & BLE_LL_AUX_HAS_ADDRA) { - adv_addr = aux_data->addr; - txadd = aux_data->addr_type; + if (aux_data->flags & BLE_LL_AUX_HAS_ADVA) { + adv_addr = aux_data->adva; + txadd = aux_data->adva_type; } - if (aux_data->flags & BLE_LL_AUX_HAS_DIR_ADDRA) { - init_addr = aux_data->dir_addr; - init_addr_type = aux_data->dir_addr_type; + if (aux_data->flags & BLE_LL_AUX_HAS_TARGETA) { + init_addr = aux_data->targeta; + init_addr_type = aux_data->targeta_type; } is_addr_decoded = true; From d8930b109e3bb8cf514375877ed10dc03dfccb4a Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Fri, 22 Nov 2019 19:45:09 +0100 Subject: [PATCH 2/4] nimble/ll: Cleanup local address vals in scan_rx_isr_end Local variables used to store addresses have confusing names. This changes them to better reflect their contents: - 'adva' is AdvA from PDU - 'targeta' is TargetA from PDU - 'adv_addr' is actual advertiser address, i.e. AdvA or identity Each variable has coresponding type variable with '_type' suffix. --- nimble/controller/src/ble_ll_scan.c | 71 +++++++++++++++-------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index c5eefd805..35698ffad 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -2205,12 +2205,12 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) int index; int resolved; uint8_t pdu_type; - uint8_t addr_type; - uint8_t peer_addr_type = 0; - uint8_t *adv_addr = NULL; - uint8_t *peer = NULL; - uint8_t *inita = NULL; - uint8_t inita_type = 0; + uint8_t adva_type = 0; + uint8_t *adva = NULL; /* Original AdvA */ + uint8_t targeta_type = 0; + uint8_t *targeta = NULL; /* Original TargetA */ + uint8_t adv_addr_type = 0; + uint8_t *adv_addr = NULL; /* Actual advertiser address (AdvA or identity) */ uint8_t *rxbuf; struct ble_mbuf_hdr *ble_hdr; struct ble_ll_scan_sm *scansm; @@ -2294,12 +2294,12 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) aux_data = ble_hdr->rxinfo.user_data; if (aux_data->flags & BLE_LL_AUX_HAS_ADVA) { - peer = aux_data->adva; - peer_addr_type = aux_data->adva_type; + adva = aux_data->adva; + adva_type = aux_data->adva_type; } if (aux_data->flags & BLE_LL_AUX_HAS_TARGETA) { - inita = aux_data->targeta; - inita_type = aux_data->targeta_type; + targeta = aux_data->targeta; + targeta_type = aux_data->targeta_type; } rc = -1; @@ -2307,8 +2307,8 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) #endif default: /* Try to decode addresses from PDU */ - if (ble_ll_scan_adv_decode_addr(pdu_type, rxbuf, ble_hdr, &peer, - &peer_addr_type, &inita, &inita_type, + if (ble_ll_scan_adv_decode_addr(pdu_type, rxbuf, ble_hdr, &adva, + &adva_type, &targeta, &targeta_type, &ext_adv_mode)) { goto scan_rx_isr_exit; } @@ -2324,7 +2324,7 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) switch (pdu_type) { #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) case BLE_ADV_PDU_TYPE_ADV_EXT_IND: - if (!peer) { + if (!adva) { /*Wait for AUX ptr */ goto scan_rx_isr_exit; } @@ -2352,11 +2352,9 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) break; } - /* Since peer might point to different address e.g. resolved one - * lets do a copy of pointers for scan request - */ - adv_addr = peer; - addr_type = peer_addr_type; + /* Use AdvA as initial advertiser address, we may try to resolve it later */ + adv_addr = adva; + adv_addr_type = adva_type; if ((scanphy->scan_filt_policy & 1) == 0) { chk_wl = 0; @@ -2369,7 +2367,7 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) * is it possible that AdvA is present either in ADV_EXT_IND or AUX_ADV_IND */ if (ble_ll_resolv_enabled()) { - if (ble_ll_is_rpa(peer, peer_addr_type)) { + if (ble_ll_is_rpa(adva, adva_type)) { if (resolve_peer) { index = ble_hw_resolv_list_match(); } else { @@ -2389,11 +2387,13 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) aux_data->rpa_index = index; } #endif - peer = g_ble_ll_resolv_list[index].rl_identity_addr; - peer_addr_type = g_ble_ll_resolv_list[index].rl_addr_type; + + /* Use resolved identity address as advertiser address */ + adv_addr = g_ble_ll_resolv_list[index].rl_identity_addr; + adv_addr_type = g_ble_ll_resolv_list[index].rl_addr_type; resolved = 1; - if (ble_ll_is_rpa(inita, inita_type)) { - if (!ble_ll_resolv_rpa(inita, g_ble_ll_resolv_list[index].rl_local_irk)) { + if (ble_ll_is_rpa(targeta, targeta_type)) { + if (!ble_ll_resolv_rpa(targeta, g_ble_ll_resolv_list[index].rl_local_irk)) { goto scan_rx_isr_exit; } ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_INITA_RESOLVED; @@ -2403,20 +2403,20 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) goto scan_rx_isr_exit; } /* We don't know peer and InitA is RPA so nothing to do more here */ - if (chk_send_req && inita && ble_ll_is_rpa(inita, inita_type)) { + if (chk_send_req && targeta && ble_ll_is_rpa(targeta, targeta_type)) { goto scan_rx_isr_exit; } } - } else if (chk_send_req && inita && ble_ll_is_rpa(inita, inita_type)) { + } else if (chk_send_req && targeta && ble_ll_is_rpa(targeta, targeta_type)) { /* If remote is identity address but InitA is RPA, make sure we can resolve it. * If not, nothing more to do here */ - rl = ble_ll_resolv_list_find(peer, peer_addr_type); + rl = ble_ll_resolv_list_find(adva, adva_type); if (!rl) { goto scan_rx_isr_exit; } - if (!ble_ll_resolv_rpa(inita, rl->rl_local_irk)) { + if (!ble_ll_resolv_rpa(targeta, rl->rl_local_irk)) { goto scan_rx_isr_exit; } @@ -2426,13 +2426,13 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) ble_hdr->rxinfo.rpa_index = index; #else - if (chk_send_req && inita && ble_ll_is_rpa(inita, inita_type)) { + if (chk_send_req && targeta && ble_ll_is_rpa(targeta, targeta_type)) { goto scan_rx_isr_exit; } #endif /* If whitelist enabled, check to see if device is in the white list */ - if (chk_wl && !ble_ll_whitelist_match(peer, peer_addr_type, resolved)) { + if (chk_wl && !ble_ll_whitelist_match(adv_addr, adv_addr_type, resolved)) { goto scan_rx_isr_exit; } ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_DEVMATCH; @@ -2444,8 +2444,8 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) /* Let us check if InitA is our device. * Note that InitA RPA is handled above where privacy is handled */ - if (inita && !ble_ll_is_rpa(inita, inita_type) && - !ble_ll_is_our_devaddr(inita, inita_type)) { + if (targeta && !ble_ll_is_rpa(targeta, targeta_type) && + !ble_ll_is_our_devaddr(targeta, targeta_type)) { goto scan_rx_isr_exit; } @@ -2455,18 +2455,18 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) */ goto scan_rx_isr_exit; } - if (ble_ll_scan_have_rxd_scan_rsp(peer, peer_addr_type, 1, adi)) { + if (ble_ll_scan_have_rxd_scan_rsp(adv_addr, adv_addr_type, 1, adi)) { goto scan_rx_isr_exit; } } else { /* Dont send scan request if we have sent one to this advertiser */ - if (ble_ll_scan_have_rxd_scan_rsp(peer, peer_addr_type, 0, 0)) { + if (ble_ll_scan_have_rxd_scan_rsp(adv_addr, adv_addr_type, 0, 0)) { goto scan_rx_isr_exit; } } #else /* Dont send scan request if we have sent one to this advertiser */ - if (ble_ll_scan_have_rxd_scan_rsp(peer, peer_addr_type, 0, 0)) { + if (ble_ll_scan_have_rxd_scan_rsp(adv_addr, adv_addr_type, 0, 0)) { goto scan_rx_isr_exit; } #endif @@ -2488,7 +2488,8 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) } #endif /* XXX: TODO assume we are on correct phy */ - ble_ll_scan_req_pdu_prepare(scansm, adv_addr, addr_type, index); + /* Use original AdvA in scan request */ + ble_ll_scan_req_pdu_prepare(scansm, adva, adva_type, index); rc = ble_phy_tx(ble_ll_scan_req_tx_pdu_cb, scansm, BLE_PHY_TRANSITION_TX_RX); From f8251a2e3bedda17e97a3f48bb37fb5c55f0c154 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Fri, 22 Nov 2019 19:45:09 +0100 Subject: [PATCH 3/4] nimble/ll: Cleanup local address vals in scan_rx_pkt_in This is the same as previous commit, just for scan_rx_pkt_in. --- nimble/controller/src/ble_ll_scan.c | 87 +++++++++++++++-------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index 35698ffad..b611eb617 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -3060,14 +3060,14 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd struct ble_ll_resolv_entry *rl; #endif uint8_t *rxbuf = om->om_data; - uint8_t *adv_addr = NULL; - uint8_t *adva; - uint8_t *ident_addr; - uint8_t ident_addr_type; - uint8_t *init_addr = NULL; - uint8_t init_addr_type = 0; - uint8_t txadd = 0; - uint8_t rxadd; + uint8_t adva_type = 0; + uint8_t *adva = NULL; /* Original AdvA */ + uint8_t targeta_type = 0; + uint8_t *targeta = NULL; /* Original TargetA */ + uint8_t adv_addr_type = 0; + uint8_t *adv_addr = NULL; /* Actual advertiser address (AdvA or identity) */ + uint8_t sreq_adva_type = 0; + uint8_t *sreq_adva; /* AdvA from scan request */ uint8_t scan_rsp_rxd; int backoff_success = 0; struct ble_ll_scan_sm *scansm = &g_ble_ll_scan_sm; @@ -3115,12 +3115,12 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd ext_adv_mode = rxbuf[2] >> 6; if (aux_data->flags & BLE_LL_AUX_HAS_ADVA) { - adv_addr = aux_data->adva; - txadd = aux_data->adva_type; + adva = aux_data->adva; + adva_type = aux_data->adva_type; } if (aux_data->flags & BLE_LL_AUX_HAS_TARGETA) { - init_addr = aux_data->targeta; - init_addr_type = aux_data->targeta_type; + targeta = aux_data->targeta; + targeta_type = aux_data->targeta_type; } is_addr_decoded = true; @@ -3128,36 +3128,36 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd #endif if (!is_addr_decoded) { - if (ble_ll_scan_adv_decode_addr(ptype, rxbuf, hdr, &adv_addr, &txadd, - &init_addr, &init_addr_type, + if (ble_ll_scan_adv_decode_addr(ptype, rxbuf, hdr, &adva, &adva_type, + &targeta, &targeta_type, &ext_adv_mode)) { goto scan_continue; } is_addr_decoded = true; } - ident_addr = adv_addr; - ident_addr_type = txadd; + adv_addr = adva; + adv_addr_type = adva_type; #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) index = hdr->rxinfo.rpa_index; if (index >= 0) { - ident_addr = g_ble_ll_resolv_list[index].rl_identity_addr; - ident_addr_type = g_ble_ll_resolv_list[index].rl_addr_type; + adv_addr = g_ble_ll_resolv_list[index].rl_identity_addr; + adv_addr_type = g_ble_ll_resolv_list[index].rl_addr_type; - if (ble_ll_is_rpa(init_addr, init_addr_type)) { + if (ble_ll_is_rpa(targeta, targeta_type)) { /* Let's try resolve InitA. */ - if (ble_ll_resolv_rpa(init_addr, g_ble_ll_resolv_list[index].rl_local_irk)) { - init_addr = ble_ll_get_our_devaddr(scansm->own_addr_type & 1); - init_addr_type = scansm->own_addr_type & 1; + if (ble_ll_resolv_rpa(targeta, g_ble_ll_resolv_list[index].rl_local_irk)) { + targeta = ble_ll_get_our_devaddr(scansm->own_addr_type & 1); + targeta_type = scansm->own_addr_type & 1; } } - } else if (init_addr && ble_ll_resolv_enabled() && ble_ll_is_rpa(init_addr, init_addr_type)) { + } else if (targeta && ble_ll_resolv_enabled() && ble_ll_is_rpa(targeta, targeta_type)) { /* If we are here it means AdvA is identity. Check if initA is RPA */ - rl = ble_ll_resolv_list_find(ident_addr, ident_addr_type); - if (rl && ble_ll_resolv_rpa(init_addr, rl->rl_local_irk)) { - init_addr = ble_ll_get_our_devaddr(scansm->own_addr_type & 1); - init_addr_type = scansm->own_addr_type & 1; + rl = ble_ll_resolv_list_find(adva, adva_type); + if (rl && ble_ll_resolv_rpa(targeta, rl->rl_local_irk)) { + targeta = ble_ll_get_our_devaddr(scansm->own_addr_type & 1); + targeta_type = scansm->own_addr_type & 1; } } #endif @@ -3167,25 +3167,26 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd * policy if PDU and adv type match and advertiser address is present */ if ((ptype == BLE_ADV_PDU_TYPE_ADV_EXT_IND) && - (ext_adv_mode == BLE_LL_EXT_ADV_MODE_NON_CONN) && adv_addr) { - check_periodic_sync(om, hdr, adv_addr, txadd, index); + (ext_adv_mode == BLE_LL_EXT_ADV_MODE_NON_CONN) && adva) { + check_periodic_sync(om, hdr, adva, adva_type, index); } #endif /* Check the scanner filter policy */ - if (ble_ll_scan_chk_filter_policy(ptype, adv_addr, txadd, init_addr, - init_addr_type, + if (ble_ll_scan_chk_filter_policy(ptype, adva, adva_type, targeta, + targeta_type, BLE_MBUF_HDR_DEVMATCH(hdr))) { goto scan_continue; } if (ptype == BLE_ADV_PDU_TYPE_SCAN_RSP) { - rxadd = scansm->pdu_data.hdr_byte & BLE_ADV_PDU_HDR_RXADD_MASK; - adva = scansm->pdu_data.adva; - if (scan_rsp_rxd && ((txadd && rxadd) || ((txadd + rxadd) == 0)) && - !memcmp(adv_addr, adva, BLE_DEV_ADDR_LEN)) { + sreq_adva_type = ble_ll_get_addr_type(scansm->pdu_data.hdr_byte & BLE_ADV_PDU_HDR_RXADD_MASK); + sreq_adva = scansm->pdu_data.adva; + if (scan_rsp_rxd && ((adva_type && sreq_adva_type) || + ((adva_type + sreq_adva_type) == 0)) && + !memcmp(adva, sreq_adva, BLE_DEV_ADDR_LEN)) { /* We have received a scan response. Add to list */ - ble_ll_scan_add_scan_rsp_adv(ident_addr, ident_addr_type, 0, 0); + ble_ll_scan_add_scan_rsp_adv(adv_addr, adv_addr_type, 0, 0); backoff_success = 1; } else { /* This is not addressed for us, ignore */ @@ -3224,9 +3225,9 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd /* Filter duplicates */ if (!scansm->scan_filt_dups || - !ble_ll_scan_dup_check_ext(ident_addr_type, ident_addr, aux_data)) { - rc = ble_ll_hci_send_ext_adv_report(ptype, ident_addr, ident_addr_type, - init_addr, init_addr_type, om, hdr); + !ble_ll_scan_dup_check_ext(adv_addr_type, adv_addr, aux_data)) { + rc = ble_ll_hci_send_ext_adv_report(ptype, adv_addr, adv_addr_type, + targeta, targeta_type, om, hdr); if ((rc < 0) && BLE_MBUF_HDR_WAIT_AUX(hdr)) { /* Data were truncated, stop scanning for subsequent chains */ hdr->rxinfo.flags &= ~BLE_MBUF_HDR_F_AUX_PTR_WAIT; @@ -3240,7 +3241,7 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd aux_error = true; } else if ((rc == 0) && scansm->scan_filt_dups) { /* Complete data were send, now we can update scan_dup list */ - ble_ll_scan_dup_update_ext(ident_addr_type, ident_addr, aux_data); + ble_ll_scan_dup_update_ext(adv_addr_type, adv_addr, aux_data); } } @@ -3268,10 +3269,10 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd /* Filter duplicates */ if (!scansm->scan_filt_dups || - !ble_ll_scan_dup_check_legacy(ident_addr_type, ident_addr, ptype)) { + !ble_ll_scan_dup_check_legacy(adv_addr_type, adv_addr, ptype)) { /* Send the advertising report, also updates scan duplicates list */ - ble_ll_scan_send_adv_report(ptype, ident_addr, ident_addr_type, - init_addr, init_addr_type, om, hdr, scansm); + ble_ll_scan_send_adv_report(ptype, adv_addr, adv_addr_type, + targeta, targeta_type, om, hdr, scansm); } scan_continue: From 5221a5f10bcde923a4ae590c1b9c57ed6ca3391b Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Sat, 23 Nov 2019 00:02:46 +0100 Subject: [PATCH 4/4] nimble/ll: Rename local var index to rpa_index This is to make it consistent with field name in structs which basically keep the same information. --- nimble/controller/src/ble_ll_scan.c | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index b611eb617..c1115c739 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -2202,7 +2202,7 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) int rc; int chk_send_req; int chk_wl; - int index; + int rpa_index; int resolved; uint8_t pdu_type; uint8_t adva_type = 0; @@ -2361,7 +2361,7 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) } resolved = 0; - index = -1; + rpa_index = -1; #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) /* Only resolve if packet actually contained AdvA. With Extended Advertising * is it possible that AdvA is present either in ADV_EXT_IND or AUX_ADV_IND @@ -2369,31 +2369,31 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) if (ble_ll_resolv_enabled()) { if (ble_ll_is_rpa(adva, adva_type)) { if (resolve_peer) { - index = ble_hw_resolv_list_match(); + rpa_index = ble_hw_resolv_list_match(); } else { #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) /* for legacy PDUs we always attempt to resolve */ BLE_LL_ASSERT(aux_data); - index = aux_data->rpa_index; + rpa_index = aux_data->rpa_index; #else BLE_LL_ASSERT(false); #endif } - if (index >= 0) { + if (rpa_index >= 0) { ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_RESOLVED; #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV) if (aux_data) { - aux_data->rpa_index = index; + aux_data->rpa_index = rpa_index; } #endif /* Use resolved identity address as advertiser address */ - adv_addr = g_ble_ll_resolv_list[index].rl_identity_addr; - adv_addr_type = g_ble_ll_resolv_list[index].rl_addr_type; + adv_addr = g_ble_ll_resolv_list[rpa_index].rl_identity_addr; + adv_addr_type = g_ble_ll_resolv_list[rpa_index].rl_addr_type; resolved = 1; if (ble_ll_is_rpa(targeta, targeta_type)) { - if (!ble_ll_resolv_rpa(targeta, g_ble_ll_resolv_list[index].rl_local_irk)) { + if (!ble_ll_resolv_rpa(targeta, g_ble_ll_resolv_list[rpa_index].rl_local_irk)) { goto scan_rx_isr_exit; } ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_INITA_RESOLVED; @@ -2424,7 +2424,7 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) } } - ble_hdr->rxinfo.rpa_index = index; + ble_hdr->rxinfo.rpa_index = rpa_index; #else if (chk_send_req && targeta && ble_ll_is_rpa(targeta, targeta_type)) { goto scan_rx_isr_exit; @@ -2489,7 +2489,7 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok) #endif /* XXX: TODO assume we are on correct phy */ /* Use original AdvA in scan request */ - ble_ll_scan_req_pdu_prepare(scansm, adva, adva_type, index); + ble_ll_scan_req_pdu_prepare(scansm, adva, adva_type, rpa_index); rc = ble_phy_tx(ble_ll_scan_req_tx_pdu_cb, scansm, BLE_PHY_TRANSITION_TX_RX); @@ -3056,7 +3056,7 @@ void ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hdr) { #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) - int index; + int rpa_index; struct ble_ll_resolv_entry *rl; #endif uint8_t *rxbuf = om->om_data; @@ -3140,14 +3140,14 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd adv_addr_type = adva_type; #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) - index = hdr->rxinfo.rpa_index; - if (index >= 0) { - adv_addr = g_ble_ll_resolv_list[index].rl_identity_addr; - adv_addr_type = g_ble_ll_resolv_list[index].rl_addr_type; + rpa_index = hdr->rxinfo.rpa_index; + if (rpa_index >= 0) { + adv_addr = g_ble_ll_resolv_list[rpa_index].rl_identity_addr; + adv_addr_type = g_ble_ll_resolv_list[rpa_index].rl_addr_type; if (ble_ll_is_rpa(targeta, targeta_type)) { /* Let's try resolve InitA. */ - if (ble_ll_resolv_rpa(targeta, g_ble_ll_resolv_list[index].rl_local_irk)) { + if (ble_ll_resolv_rpa(targeta, g_ble_ll_resolv_list[rpa_index].rl_local_irk)) { targeta = ble_ll_get_our_devaddr(scansm->own_addr_type & 1); targeta_type = scansm->own_addr_type & 1; } @@ -3168,7 +3168,7 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd */ if ((ptype == BLE_ADV_PDU_TYPE_ADV_EXT_IND) && (ext_adv_mode == BLE_LL_EXT_ADV_MODE_NON_CONN) && adva) { - check_periodic_sync(om, hdr, adva, adva_type, index); + check_periodic_sync(om, hdr, adva, adva_type, rpa_index); } #endif