Skip to content

Commit c718ef7

Browse files
sondrepasilz
andcommitted
bluetooth: services: hrs role fix
Only run ble evt when peripheral role is connected. Signed-off-by: Sondre Pettersen <sondre.pettersen@nordicsemi.no> Co-authored-by: Asil Zogby <asil.zogby@nordicsemi.no>
1 parent 1b5a1d8 commit c718ef7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

  • subsys/bluetooth/services/ble_hrs

subsys/bluetooth/services/ble_hrs/hrs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ void ble_hrs_on_ble_evt(const ble_evt_t *ble_evt, void *hrs_instance)
193193
__ASSERT(ble_evt, "BLE event is NULL");
194194
__ASSERT(hrs_instance, "BLE instance is NULL");
195195

196+
/* Filter:
197+
* Only handle peripheral-role GAP events.
198+
* Central-role events would otherwise overwrite hrs->conn_handle and break notifications
199+
* to the real peer.
200+
*/
201+
if (ble_evt->header.evt_id >= BLE_GAP_EVT_BASE &&
202+
ble_evt->header.evt_id <= BLE_GAP_EVT_LAST &&
203+
ble_evt->evt.gap_evt.params.connected.role != BLE_GAP_ROLE_PERIPH &&
204+
ble_evt->evt.gap_evt.params.connected.role != BLE_GAP_ROLE_INVALID) {
205+
return;
206+
}
207+
196208
switch (ble_evt->header.evt_id) {
197209
case BLE_GAP_EVT_CONNECTED:
198210
on_connect(hrs_instance, &ble_evt->evt.gap_evt);

0 commit comments

Comments
 (0)