Skip to content

Commit 6f24078

Browse files
committed
Nordic BLE: route event handling correctly.
1 parent 167a660 commit 6f24078

File tree

1 file changed

+12
-45
lines changed
  • features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5x/source/btle

1 file changed

+12
-45
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5x/source/btle/btle.cpp

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ void btle_handler(const ble_evt_t *p_ble_evt)
272272
(void)p_context; // Keep compiler happy
273273
#endif
274274
using ble::pal::vendor::nordic::nRF5xGattClient;
275+
using ble::pal::vendor::nordic::nRF5xSecurityManager;
275276

276277
// In SDK14+, all other modules from the SDK will be registered independently as softdevice events observers
277278
#if !NRF_SDK14PLUS_EVENT_HANDLERS
@@ -299,42 +300,16 @@ void btle_handler(const ble_evt_t *p_ble_evt)
299300
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
300301
nRF5xGap &gap = (nRF5xGap &) ble.getGap();
301302
nRF5xGattServer &gattServer = (nRF5xGattServer &) ble.getGattServer();
302-
nRF5xSecurityManager &securityManager = (nRF5xSecurityManager &) ble.getSecurityManager();
303+
nRF5xSecurityManager &securityManager = nRF5xSecurityManager::get_security_manager();
303304

304305
/* Custom event handler */
305306
switch (p_ble_evt->header.evt_id) {
306-
case BLE_GAP_EVT_CONNECTED: {
307-
Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
308-
#if defined(TARGET_MCU_NRF51_16K_S110) || defined(TARGET_MCU_NRF51_32K_S110)
309-
/* Only peripheral role is supported by S110 */
310-
Gap::Role_t role = Gap::PERIPHERAL;
311-
#else
312-
Gap::Role_t role = static_cast<Gap::Role_t>(p_ble_evt->evt.gap_evt.params.connected.role);
313-
#endif
314-
gap.setConnectionHandle(handle);
315-
const Gap::ConnectionParams_t *params = reinterpret_cast<const Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params));
316-
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
317-
#if (NRF_SD_BLE_API_VERSION <= 2)
318-
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
319-
320-
gap.processConnectionEvent(handle,
321-
role,
322-
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
323-
static_cast<BLEProtocol::AddressType_t>(own->addr_type), own->addr,
324-
params);
325-
#else
326-
Gap::AddressType_t addr_type;
327-
Gap::Address_t own_address;
328-
gap.getAddress(&addr_type, own_address);
329-
330-
gap.processConnectionEvent(handle,
331-
role,
332-
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
333-
addr_type, own_address,
334-
params);
335-
#endif
307+
case BLE_GAP_EVT_CONNECTED:
308+
gap.on_connection(
309+
p_ble_evt->evt.gap_evt.conn_handle,
310+
p_ble_evt->evt.gap_evt.params.connected
311+
);
336312
break;
337-
}
338313

339314
case BLE_GAP_EVT_DISCONNECTED: {
340315
Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
@@ -416,10 +391,6 @@ void btle_handler(const ble_evt_t *p_ble_evt)
416391
}
417392
#endif
418393

419-
case BLE_GAP_EVT_PASSKEY_DISPLAY:
420-
securityManager.processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
421-
break;
422-
423394
case BLE_GAP_EVT_TIMEOUT:
424395
gap.processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src));
425396
break;
@@ -431,21 +402,17 @@ void btle_handler(const ble_evt_t *p_ble_evt)
431402
// BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION));
432403
break;
433404

434-
case BLE_GAP_EVT_ADV_REPORT: {
435-
const ble_gap_evt_adv_report_t *advReport = &p_ble_evt->evt.gap_evt.params.adv_report;
436-
gap.processAdvertisementReport(advReport->peer_addr.addr,
437-
advReport->rssi,
438-
advReport->scan_rsp,
439-
static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type),
440-
advReport->dlen,
441-
advReport->data);
405+
case BLE_GAP_EVT_ADV_REPORT:
406+
gap.on_advertising_packet(p_ble_evt->evt.gap_evt.params.adv_report);
442407
break;
443-
}
444408

445409
default:
446410
break;
447411
}
448412

413+
// Process security manager events
414+
securityManager.sm_handler(p_ble_evt);
415+
449416
gattServer.hwCallback(p_ble_evt);
450417
}
451418

0 commit comments

Comments
 (0)