Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
Revision 127:bd1e1fe607e0, committed 2015-05-08
- Comitter:
- rgrover1
- Date:
- Fri May 08 15:33:55 2015 +0100
- Parent:
- 126:e6114201f092
- Child:
- 128:b7fc7925b5da
- Commit message:
- Synchronized with git rev 7b0a9a79
Author: Rohit Grover
add handling for initializeSecurity()
Changed in this revision
--- a/btle/btle.cpp Fri May 08 15:33:55 2015 +0100 +++ b/btle/btle.cpp Fri May 08 15:33:55 2015 +0100 @@ -92,12 +92,24 @@ ASSERT_STATUS( softdevice_ble_evt_handler_set(btle_handler)); ASSERT_STATUS( softdevice_sys_evt_handler_set(sys_evt_dispatch)); - pstorage_init(); + btle_gap_init(); + + return ERROR_NONE; +} + +ble_error_t +btle_initializeSecurity() +{ + if (pstorage_init() != NRF_SUCCESS) { + return BLE_ERROR_UNSPECIFIED; + } dm_init_param_t dm_init_param = { .clear_persistent_data = false /* Set to true in case the module should clear all persistent data. */ }; - dm_init(&dm_init_param); + if (dm_init(&dm_init_param) != NRF_SUCCESS) { + return BLE_ERROR_UNSPECIFIED; + } uint8_t applicationInstance; const dm_application_param_t dm_param = { @@ -117,17 +129,39 @@ }, /**< Key distribution bitmap: keys that the peripheral device will distribute. */ } }; - dm_register(&applicationInstance, &dm_param); - btle_gap_init(); + ret_code_t rc; + if ((rc = dm_register(&applicationInstance, &dm_param)) != NRF_SUCCESS) { + switch (rc) { + case NRF_ERROR_INVALID_STATE: + return BLE_ERROR_INVALID_STATE; + case NRF_ERROR_NO_MEM: + return BLE_ERROR_NO_MEM; + default: + return BLE_ERROR_UNSPECIFIED; + } + } - return ERROR_NONE; + return BLE_ERROR_NONE; } ret_code_t dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t event_result) { printf("dm_handler: event %u\r\n", p_event->event_id); + + switch (p_event->event_id) { + case DM_EVT_SECURITY_SETUP: /* started */ + break; + case DM_EVT_SECURITY_SETUP_COMPLETE: + break; + case DM_EVT_LINK_SECURED: + break; + case DM_EVT_DEVICE_CONTEXT_STORED: + break; + default: + break; + } return NRF_SUCCESS; }
--- a/btle/btle.h Fri May 08 15:33:55 2015 +0100 +++ b/btle/btle.h Fri May 08 15:33:55 2015 +0100 @@ -26,10 +26,11 @@ #include "ble_srv_common.h" #include "ble.h" -error_t btle_init(void); +error_t btle_init(void); +ble_error_t btle_initializeSecurity(void); #ifdef __cplusplus } #endif -#endif // ifndef _BTLE_H_ +#endif // ifndef _BTLE_H_ \ No newline at end of file
--- a/nRF51822n.h Fri May 08 15:33:55 2015 +0100 +++ b/nRF51822n.h Fri May 08 15:33:55 2015 +0100 @@ -22,6 +22,7 @@ #include "BLEDevice.h" #include "nRF51Gap.h" #include "nRF51GattServer.h" +#include "btle.h" class nRF51822n : public BLEDeviceInstanceBase { @@ -44,6 +45,7 @@ virtual ble_error_t init(void); virtual ble_error_t shutdown(void); virtual ble_error_t reset(void); + virtual ble_error_t initializeSecurity(void) {return btle_initializeSecurity();} virtual void waitForEvent(void); };