add handling for initializeSecurity()
This commit is contained in:
parent
ac70594f77
commit
7b0a9a7929
3 changed files with 43 additions and 6 deletions
|
@ -92,12 +92,24 @@ error_t btle_init(void)
|
|||
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 @@ error_t btle_init(void)
|
|||
}, /**< 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ extern "C" {
|
|||
#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
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "BLEDevice.h"
|
||||
#include "nRF51Gap.h"
|
||||
#include "nRF51GattServer.h"
|
||||
#include "btle.h"
|
||||
|
||||
class nRF51822n : public BLEDeviceInstanceBase
|
||||
{
|
||||
|
@ -44,6 +45,7 @@ public:
|
|||
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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue