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:
- 2:2d9d4b271af8
- Parent:
- 1:52c48814da8e
- Child:
- 3:b852bf8d6fad
diff -r 52c48814da8e -r 2d9d4b271af8 main.cpp --- a/main.cpp Tue Jun 02 08:14:51 2015 +0000 +++ b/main.cpp Wed Jun 03 09:11:21 2015 +0000 @@ -16,7 +16,7 @@ #include "mbed.h" #include "BLEDevice.h" -#include "HeartRateService.h" +#include "HeartRateSecSampleSrv.h" #include "DeviceInformationService.h" /* Enable the following if you need to throttle the connection interval. This has @@ -28,16 +28,18 @@ BLEDevice ble; DigitalOut led1(LED1); -const static char DEVICE_NAME[] = "HRM1"; +const static char DEVICE_NAME[] = "HRM_SEC"; static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, GattService::UUID_DEVICE_INFORMATION_SERVICE}; static volatile bool triggerSensorPolling = false; void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { + printf("Disconnected!\r\n"); ble.startAdvertising(); // restart advertising } + void periodicCallback(void) { led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ @@ -46,22 +48,34 @@ * heavy-weight sensor polling from the main thread. */ triggerSensorPolling = true; } -uint8_t KEY[6] = {0x01, 0x02, 0x00, 0x00, 0x00, 0x00}; + void connectionCallback(Gap::Handle_t handle, Gap::addr_type_t peerAddrType, const Gap::Address_t peerAddr, Gap::addr_type_t ownAddrType, const Gap::Address_t ownAddr, const Gap::ConnectionParams_t * pParam) { - printf("connected!\r\n"); + printf("Connected!\r\n"); } + void passkeyDisplayCallback(Gap::Handle_t handle, const Gap::Passkey_t passkey) { uint8_t i; printf("Input passKey: "); for(i = 0; i < 6; i++) { - printf("%d ", passkey[i]); + printf("%c ", passkey[i]); + } + printf("\r\n"); +} + + +void securitySetupCompletedCallback(Gap::Handle_t handle, Gap::SecurityCompletionStatus_t status) +{ + if(!status) { + printf("Security success\r\n", status); + } else { + printf("Security failed\r\n", status); } } @@ -71,16 +85,23 @@ led1 = 1; Ticker ticker; ticker.attach(periodicCallback, 1); // blink LED every second -printf("Started\r\n"); + printf("Started\r\n"); + + /* Initialize BLE module */ ble.init(); + + /* Initialize BLE security */ ble.initializeSecurity(true, true, Gap::IO_CAPS_DISPLAY_ONLY, NULL); - //ble.initializeSecurity(); + + /* Set callback functions */ ble.onConnection(connectionCallback); ble.onDisconnection(disconnectionCallback); ble.onPasskeyDisplay(passkeyDisplayCallback); + ble.onSecuritySetupCompleted(securitySetupCompletedCallback); + /* Setup primary service. */ uint8_t hrmCounter = 100; // init HRM to 100bps - HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); + HeartRateSecService hrService(ble, hrmCounter, HeartRateSecService::LOCATION_FINGER); /* Setup auxiliary service. */ DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");