Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed-dev nRF51822
Diff: HIDController_BLE.cpp
- Revision:
- 13:b0ffdf2012b9
- Parent:
- 10:1aed2481a743
- Child:
- 15:70bf079d3ee1
--- a/HIDController_BLE.cpp Wed Aug 17 00:58:34 2016 +0000 +++ b/HIDController_BLE.cpp Sun Aug 21 05:13:45 2016 +0000 @@ -28,6 +28,8 @@ static BatteryService* batteryService; static DeviceInformationService* deviceInformationService; +static BLEProtocol::Address_t peerAddress; + static void updateBatteryLevel() { if (!batteryService) return; static const float BATTERY_MAX = 2.4; @@ -69,7 +71,8 @@ static void onConnect(const Gap::ConnectionCallbackParams_t *params) { printf("onConnect\r\n"); - // If a bond is created, the HID Device should write the address of the HID Host in the HID Device controller’s white list and set the HID Device controller’s advertising filter policy to ‘process scan and connection requests only from devices in the White List’. + peerAddress.type = params->peerAddrType; + memcpy(peerAddress.address, params->peerAddr, Gap::ADDR_LEN); } static void onDisconnect(const Gap::DisconnectionCallbackParams_t *params) { @@ -93,6 +96,19 @@ static void securitySetupCompletedCallback(Gap::Handle_t handle, SecurityManager::SecurityCompletionStatus_t status) { if (status == SecurityManager::SEC_STATUS_SUCCESS) { printf("Security success %d\r\n", status); + + printf("Set whitelist\r\n"); + Gap::Whitelist_t whitelist; + whitelist.size = 1; + whitelist.capacity = 1; + whitelist.addresses = &peerAddress; + + BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setWhitelist(whitelist); + printf("Set Advertising Policy Mode\r\n"); + // BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_SCAN_REQS); + // BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_CONN_REQS); + BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_ALL_REQS); + } else { printf("Security failed %d\r\n", status); }