Skip to content

Commit a0dc3ff

Browse files
committed
samples: ble_hrs_central: fix peripheral address filter endianness
The address set with the CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR Kconfig was incorrectly converted to big-endian before being passed to the SoftDevice API (which uses little-endian for the address). In turn, the address printed on a BLE_SCAN_EVT_CONNECTED event was also incorrect (displayed inverted). Fix both these issues so that the Kconfig and address print uses big-endian (standard way to display an address), while the libraries and SoftDevice use addresses in little-endian. Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
1 parent 29291e6 commit a0dc3ff

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Bluetooth LE samples
120120

121121
* The disconnect button handler to only disconnect on button press, and not on button release.
122122
* The allow list disabling button to only trigger on button press, and not on button release.
123+
* An issue with the endianness of the target peripheral address when displaying the address on a :c:macro:`BLE_SCAN_EVT_CONNECTED` event and when supplying scan filter address with the :kconfig:option:`CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR` Kconfig option.
123124

124125
NFC samples
125126
-----------

samples/bluetooth/ble_hrs_central/src/main.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ static bool allow_list_disabled;
5353
static atomic_t central_conn;
5454

5555
#if defined(CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR)
56-
uint8_t target_periph_addr[BLE_GAP_ADDR_LEN] = {
57-
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 40) & 0xff,
58-
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 32) & 0xff,
59-
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 24) & 0xff,
60-
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 16) & 0xff,
61-
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 8) & 0xff,
56+
/* Target peripheral address (little-endian). */
57+
static const uint8_t target_periph_addr[BLE_GAP_ADDR_LEN] = {
6258
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR) & 0xff,
59+
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 8) & 0xff,
60+
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 16) & 0xff,
61+
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 24) & 0xff,
62+
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 32) & 0xff,
63+
(CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR >> 40) & 0xff,
6364
};
6465
#endif /* CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR */
6566

@@ -529,12 +530,11 @@ static void scan_evt_handler(const struct ble_scan_evt *scan_evt)
529530
break;
530531

531532
case BLE_SCAN_EVT_CONNECTED: {
532-
const ble_gap_evt_connected_t *p_connected = scan_evt->connected.connected;
533+
const ble_gap_addr_t *const peer_addr = &scan_evt->connected.connected->peer_addr;
533534

534-
LOG_INF("Connecting to target %02x%02x%02x%02x%02x%02x",
535-
p_connected->peer_addr.addr[0], p_connected->peer_addr.addr[1],
536-
p_connected->peer_addr.addr[2], p_connected->peer_addr.addr[3],
537-
p_connected->peer_addr.addr[4], p_connected->peer_addr.addr[5]);
535+
LOG_INF("Connecting to target %02X:%02X:%02X:%02X:%02X:%02X",
536+
peer_addr->addr[5], peer_addr->addr[4], peer_addr->addr[3],
537+
peer_addr->addr[2], peer_addr->addr[1], peer_addr->addr[0]);
538538
} break;
539539

540540
default:

0 commit comments

Comments
 (0)