Skip to content

Commit cb13f44

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 43f3c50 commit cb13f44

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
@@ -52,13 +52,14 @@ static bool allow_list_disabled;
5252
static atomic_t central_conn;
5353

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

@@ -541,12 +542,11 @@ static void scan_evt_handler(const struct ble_scan_evt *scan_evt)
541542
break;
542543

543544
case BLE_SCAN_EVT_CONNECTED: {
544-
const ble_gap_evt_connected_t *p_connected = scan_evt->connected.connected;
545+
const ble_gap_addr_t *const peer_addr = &scan_evt->connected.connected->peer_addr;
545546

546-
LOG_INF("Connecting to target %02x%02x%02x%02x%02x%02x",
547-
p_connected->peer_addr.addr[0], p_connected->peer_addr.addr[1],
548-
p_connected->peer_addr.addr[2], p_connected->peer_addr.addr[3],
549-
p_connected->peer_addr.addr[4], p_connected->peer_addr.addr[5]);
547+
LOG_INF("Connecting to target %02X:%02X:%02X:%02X:%02X:%02X",
548+
peer_addr->addr[5], peer_addr->addr[4], peer_addr->addr[3],
549+
peer_addr->addr[2], peer_addr->addr[1], peer_addr->addr[0]);
550550
} break;
551551

552552
default:

0 commit comments

Comments
 (0)