Fork of BLE_SecureHeartRate : should this 'work' i.e. require a secure connection on an nRF51-DK? Hopefully I'm just missing something obvious - or is this broken?
Dependencies: BLE_API mbed nRF51822
Fork of BLE_SecureHeartRate by
Diff: main.cpp
- Revision:
- 8:32cdc49c027e
- Parent:
- 7:e8dfe1c97c71
- Child:
- 9:b1cde75ccbbc
diff -r e8dfe1c97c71 -r 32cdc49c027e main.cpp --- a/main.cpp Tue Sep 29 12:05:32 2015 +0000 +++ b/main.cpp Tue May 24 12:04:42 2016 +0000 @@ -26,10 +26,16 @@ static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, GattService::UUID_DEVICE_INFORMATION_SERVICE}; static volatile bool triggerSensorPolling = false; +Gap::Handle_t connectionHandle; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { - printf("Disconnected!\r\n"); + if (params->handle == connectionHandle) { + printf("Disconnected from %i!\r\n", params->handle); + connectionHandle = 0; + } else { + printf("Disconnected from handle %i while state claims handle %i\r\n", params->handle, connectionHandle); + } ble.startAdvertising(); // restart advertising } @@ -44,7 +50,10 @@ void connectionCallback(const Gap::ConnectionCallbackParams_t *params) { - printf("Connected!\r\n"); + // connection handle is: + connectionHandle = params ? params->handle : NULL; + + printf("Connected to %i!\r\n", connectionHandle); } void passkeyDisplayCallback(Gap::Handle_t handle, const SecurityManager::Passkey_t passkey) @@ -77,7 +86,11 @@ /* Initialize BLE security */ bool enableBonding = true; bool requireMITM = true; - ble.securityManager().init(enableBonding, requireMITM, SecurityManager::IO_CAPS_DISPLAY_ONLY); + uint8_t pass[6] = {'1', '2', '3', '4', '5', '6'}; + ble.securityManager().init(enableBonding, requireMITM, SecurityManager::IO_CAPS_NONE, pass); + // to see if the behaviour is any different, try claiming we have Keyboard & Display capability on this peripheral + // also making sure to no longer specify a static password + //ble.securityManager().init(enableBonding, requireMITM, SecurityManager::IO_CAPS_KEYBOARD_DISPLAY, NULL); /* Set callback functions */ ble.gap().onConnection(connectionCallback); @@ -119,6 +132,9 @@ // update bps hrService.updateHeartRate(hrmCounter); + + // DEBUG output + hrService.outputSecurityStatus(connectionHandle); } else { ble.waitForEvent(); // low power wait for event }