Skip to content

Commit ae4a53e

Browse files
Support to BlueNRG_2 BLE component (#13246)
Add support to BlueNRG_2 BLE component Signed-off-by: Andrea Palmieri <andrea.palmieri@st.com> Co-authored-by: Andrea Palmieri <andrea.palmieri@st.com> Co-authored-by: Paul Szczeanek <paul.szczepanek@arm.com>
1 parent 89bd565 commit ae4a53e

File tree

16 files changed

+892
-28
lines changed

16 files changed

+892
-28
lines changed

connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/hci/dual_chip/hci_evt.c

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,30 @@ static void hciEvtParseLeConnCmpl(hciEvt_t *pMsg, uint8_t *p, uint8_t len)
367367
pMsg->hdr.status = pMsg->leConnCmpl.status;
368368
}
369369

370+
#ifndef CORDIO_RPA_SWAP_WORKAROUND
371+
#define CORDIO_RPA_SWAP_WORKAROUND 0
372+
#endif
373+
#if CORDIO_RPA_SWAP_WORKAROUND
374+
/*************************************************************************************************/
375+
/*!
376+
* \brief Check if address bits are all 0s or all 1s.
377+
*
378+
* \param p Pointer to address.
379+
*
380+
* \return TRUE if address is invalid.
381+
*/
382+
/*************************************************************************************************/
383+
static bool_t isAddressInvalid(uint8_t *p)
384+
{
385+
for (int i = 0; i < 6; i++) {
386+
if ((p[i] != 0xff) && (p[i] != 0x00)) {
387+
return FALSE; // meaning valid address
388+
}
389+
}
390+
return TRUE;
391+
}
392+
#endif // CORDIO_RPA_SWAP_WORKAROUND
393+
370394
/*************************************************************************************************/
371395
/*!
372396
* \brief Parse an HCI event.
@@ -384,9 +408,21 @@ static void hciEvtParseLeEnhancedConnCmpl(hciEvt_t *pMsg, uint8_t *p, uint8_t le
384408
BSTREAM_TO_UINT16(pMsg->leConnCmpl.handle, p);
385409
BSTREAM_TO_UINT8(pMsg->leConnCmpl.role, p);
386410
BSTREAM_TO_UINT8(pMsg->leConnCmpl.addrType, p);
387-
BSTREAM_TO_BDA(pMsg->leConnCmpl.peerAddr, p);
388-
BSTREAM_TO_BDA(pMsg->leConnCmpl.localRpa, p);
389-
BSTREAM_TO_BDA(pMsg->leConnCmpl.peerRpa, p);
411+
412+
#if CORDIO_RPA_SWAP_WORKAROUND
413+
if (isAddressInvalid(p)) {
414+
memset(pMsg->leConnCmpl.peerRpa, 0x00, BDA_ADDR_LEN);
415+
p += BDA_ADDR_LEN;
416+
BSTREAM_TO_BDA(pMsg->leConnCmpl.localRpa, p);
417+
BSTREAM_TO_BDA(pMsg->leConnCmpl.peerAddr, p);
418+
} else
419+
#endif // CORDIO_RPA_SWAP_WORKAROUND
420+
{
421+
BSTREAM_TO_BDA(pMsg->leConnCmpl.peerAddr, p);
422+
BSTREAM_TO_BDA(pMsg->leConnCmpl.localRpa, p);
423+
BSTREAM_TO_BDA(pMsg->leConnCmpl.peerRpa, p);
424+
}
425+
390426
BSTREAM_TO_UINT16(pMsg->leConnCmpl.connInterval, p);
391427
BSTREAM_TO_UINT16(pMsg->leConnCmpl.connLatency, p);
392428
BSTREAM_TO_UINT16(pMsg->leConnCmpl.supTimeout, p);

connectivity/FEATURE_BLE/source/cordio/mbed_lib.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@
7676
"help": "Maximum number of EATT channels per DM connection.",
7777
"value": 1,
7878
"macro_name": "EATT_CONN_CHAN_MAX"
79+
},
80+
"rpa-swap-workaround": {
81+
"help": "Check connection complete event if it needs the addresses swapped due to bug in controller",
82+
"value": null,
83+
"macro_name": "CORDIO_RPA_SWAP_WORKAROUND"
84+
}
85+
},
86+
"target_overrides": {
87+
"NUCLEO_WB55RG": {
88+
"rpa-swap-workaround": true
7989
}
8090
}
81-
}
91+
}

connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -401,30 +401,18 @@ class PalGap final : public ble::PalGap {
401401

402402
static GapConnectionCompleteEvent convert(const hciLeConnCmplEvt_t *conn_evt)
403403
{
404-
const bdAddr_t *peer_rpa = &conn_evt->peerRpa;
405-
const bdAddr_t *peer_address = &conn_evt->peerAddr;
406-
407-
#if defined(TARGET_MCU_STM32WB55xx)
408-
const bdAddr_t invalidAddress = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
409-
if (conn_evt->addrType == DM_ADDR_RANDOM &&
410-
memcmp(peer_address, invalidAddress, sizeof(invalidAddress)) == 0 &&
411-
memcmp(peer_rpa, invalidAddress, sizeof(invalidAddress) != 0)
412-
) {
413-
std::swap(peer_rpa, peer_address);
414-
}
415-
#endif
416404
return GapConnectionCompleteEvent(
417405
conn_evt->status,
418406
// note the usage of the stack handle, not the HCI handle
419407
conn_evt->hdr.param,
420408
(connection_role_t::type) conn_evt->role,
421409
(peer_address_type_t::type) conn_evt->addrType,
422-
*peer_address,
410+
conn_evt->peerAddr,
423411
conn_evt->connInterval,
424412
conn_evt->connLatency,
425413
conn_evt->supTimeout,
426414
conn_evt->localRpa,
427-
*peer_rpa
415+
conn_evt->peerRpa
428416
);
429417
}
430418
};

connectivity/drivers/ble/FEATURE_BLE/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
if("BlueNRG_2" IN_LIST MBED_TARGET_LABELS)
5+
add_subdirectory(COMPONENT_BlueNRG_2)
6+
endif()
7+
48
if("BlueNRG_MS" IN_LIST MBED_TARGET_LABELS)
59
add_subdirectory(COMPONENT_BlueNRG_MS)
610
endif()

0 commit comments

Comments
 (0)