21
21
#include " btle_clock.h"
22
22
23
23
#include " ble_flash.h"
24
- #include " ble_conn_params.h"
25
24
26
- #include " btle_gap.h"
27
25
#include " custom/custom_helper.h"
28
26
29
27
#include " ble/GapEvents.h"
30
28
#include " nRF5xn.h"
31
29
32
- // This is a C++ file, so C11 _Static_assert (works with -std=gnu99 on GCC) won't work
33
- #undef STATIC_ASSERT_SIMPLE
34
- #undef STATIC_ASSERT_MSG
35
-
36
- // FIXME : We can't use mbed_assert.h because we're using these macros within functions
37
- #define STATIC_ASSERT_MSG (EXPR, MSG )
38
- #define STATIC_ASSERT_SIMPLE (EXPR )
39
-
40
- #warning FIXME : We can't use mbed_assert.h because we're using these within functions
41
-
42
30
#ifdef S110
43
31
#define IS_LEGACY_DEVICE_MANAGER_ENABLED 1
44
32
#elif defined(S130) || defined(S132)
@@ -52,8 +40,6 @@ extern "C" {
52
40
#else
53
41
#include " nrf_fstorage.h"
54
42
#include " fds.h"
55
- #include " peer_manager.h"
56
- #include " ble_conn_state.h"
57
43
#endif
58
44
59
45
#include " nrf_sdh.h"
@@ -64,6 +50,16 @@ extern "C" {
64
50
65
51
#include " nRF5xPalGattClient.h"
66
52
53
+ // This is a C++ file, so C11 _Static_assert (works with -std=gnu99 on GCC) won't work
54
+ #undef STATIC_ASSERT_SIMPLE
55
+ #undef STATIC_ASSERT_MSG
56
+
57
+ // FIXME : We can't use mbed_assert.h because we're using these macros within functions
58
+ #define STATIC_ASSERT_MSG (EXPR, MSG )
59
+ #define STATIC_ASSERT_SIMPLE (EXPR )
60
+
61
+ #warning FIXME : We can't use mbed_assert.h because we're using these within functions
62
+
67
63
68
64
// Make this volatile at it will be set in interrupt context
69
65
volatile bool isEventsSignaled = false ;
@@ -76,9 +72,9 @@ void app_error_handler(uint32_t error_code, uint32_t line_num, const
76
72
extern " C" void SD_EVT_IRQHandler (void ); // export the softdevice event handler for registration by nvic-set-vector.
77
73
78
74
#if NRF_SDK14PLUS_EVENT_HANDLERS
79
- static void btle_handler (const ble_evt_t *p_ble_evt, void *p_context);
75
+ void btle_handler (const ble_evt_t *p_ble_evt, void *p_context);
80
76
#else
81
- static void btle_handler (ble_evt_t *p_ble_evt);
77
+ void btle_handler (ble_evt_t *p_ble_evt);
82
78
#endif
83
79
84
80
#if !NRF_SDK14PLUS_EVENT_HANDLERS
@@ -232,9 +228,6 @@ error_t btle_init(void)
232
228
}
233
229
#endif
234
230
235
- // Peer Manger must been initialised prior any other call to its API (this file and btle_security_pm.cpp)
236
- pm_init ();
237
-
238
231
#if (NRF_SD_BLE_API_VERSION <= 2)
239
232
ble_gap_addr_t addr;
240
233
if (sd_ble_gap_address_get (&addr) != NRF_SUCCESS) {
@@ -243,10 +236,6 @@ error_t btle_init(void)
243
236
if (sd_ble_gap_address_set (BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr) != NRF_SUCCESS) {
244
237
return ERROR_INVALID_PARAM;
245
238
}
246
- #else
247
- ble_gap_privacy_params_t privacy_params = {0 };
248
- privacy_params.privacy_mode = BLE_GAP_PRIVACY_MODE_OFF;
249
- pm_privacy_set (&privacy_params);
250
239
#endif
251
240
252
241
// From SDK 14 onwards event handlers are registered differently
@@ -259,19 +248,20 @@ error_t btle_init(void)
259
248
ASSERT_STATUS ( softdevice_sys_evt_handler_set (sys_evt_dispatch));
260
249
#endif
261
250
262
- return btle_gap_init () ;
251
+ return ERROR_NONE ;
263
252
}
264
253
265
254
#if NRF_SDK14PLUS_EVENT_HANDLERS
266
- static void btle_handler (const ble_evt_t *p_ble_evt, void *p_context)
255
+ void btle_handler (const ble_evt_t *p_ble_evt, void *p_context)
267
256
#else
268
- static void btle_handler (ble_evt_t *p_ble_evt)
257
+ void btle_handler (const ble_evt_t *p_ble_evt)
269
258
#endif
270
259
{
271
260
#if NRF_SDK14PLUS_EVENT_HANDLERS
272
261
(void )p_context; // Keep compiler happy
273
262
#endif
274
263
using ble::pal::vendor::nordic::nRF5xGattClient;
264
+ using ble::pal::vendor::nordic::nRF5xSecurityManager;
275
265
276
266
// In SDK14+, all other modules from the SDK will be registered independently as softdevice events observers
277
267
#if !NRF_SDK14PLUS_EVENT_HANDLERS
@@ -286,9 +276,6 @@ static void btle_handler(ble_evt_t *p_ble_evt)
286
276
// Forward BLE events to the Connection State module.
287
277
// This must be called before any event handler that uses this module.
288
278
ble_conn_state_on_ble_evt (p_ble_evt);
289
-
290
- // Forward BLE events to the Peer Manager
291
- pm_on_ble_evt (p_ble_evt);
292
279
#endif
293
280
#endif
294
281
@@ -299,42 +286,16 @@ static void btle_handler(ble_evt_t *p_ble_evt)
299
286
nRF5xn &ble = nRF5xn::Instance (BLE::DEFAULT_INSTANCE);
300
287
nRF5xGap &gap = (nRF5xGap &) ble.getGap ();
301
288
nRF5xGattServer &gattServer = (nRF5xGattServer &) ble.getGattServer ();
302
- nRF5xSecurityManager &securityManager = ( nRF5xSecurityManager &) ble. getSecurityManager ();
289
+ nRF5xSecurityManager &securityManager = nRF5xSecurityManager::get_security_manager ();
303
290
304
291
/* Custom event handler */
305
292
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
293
+ case BLE_GAP_EVT_CONNECTED:
294
+ gap.on_connection (
295
+ p_ble_evt->evt .gap_evt .conn_handle ,
296
+ p_ble_evt->evt .gap_evt .params .connected
297
+ );
336
298
break ;
337
- }
338
299
339
300
case BLE_GAP_EVT_DISCONNECTED: {
340
301
Gap::Handle_t handle = p_ble_evt->evt .gap_evt .conn_handle ;
@@ -416,10 +377,6 @@ static void btle_handler(ble_evt_t *p_ble_evt)
416
377
}
417
378
#endif
418
379
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
-
423
380
case BLE_GAP_EVT_TIMEOUT:
424
381
gap.processTimeoutEvent (static_cast <Gap::TimeoutSource_t>(p_ble_evt->evt .gap_evt .params .timeout .src ));
425
382
break ;
@@ -431,21 +388,17 @@ static void btle_handler(ble_evt_t *p_ble_evt)
431
388
// BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION));
432
389
break ;
433
390
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 );
391
+ case BLE_GAP_EVT_ADV_REPORT:
392
+ gap.on_advertising_packet (p_ble_evt->evt .gap_evt .params .adv_report );
442
393
break ;
443
- }
444
394
445
395
default :
446
396
break ;
447
397
}
448
398
399
+ // Process security manager events
400
+ securityManager.sm_handler (p_ble_evt);
401
+
449
402
gattServer.hwCallback (p_ble_evt);
450
403
}
451
404
0 commit comments