KeyboardStream example from BLE_HID

Dependencies:   BLE_API BLE_HID mbed nRF51822

This example is currently copied as-is from the github development repo.

Committer:
Jean-Philippe Brucker
Date:
Thu Nov 19 15:16:43 2015 +0000
Revision:
2:a0b9f9aa0e2d
Parent:
0:1484ce3a8cdf
Version 0.3

Probably breaks MacOS support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jean-Philippe Brucker 0:1484ce3a8cdf 1 /* mbed Microcontroller Library
Jean-Philippe Brucker 0:1484ce3a8cdf 2 * Copyright (c) 2015 ARM Limited
Jean-Philippe Brucker 0:1484ce3a8cdf 3 *
Jean-Philippe Brucker 0:1484ce3a8cdf 4 * Licensed under the Apache License, Version 2.0 (the "License");
Jean-Philippe Brucker 0:1484ce3a8cdf 5 * you may not use this file except in compliance with the License.
Jean-Philippe Brucker 0:1484ce3a8cdf 6 * You may obtain a copy of the License at
Jean-Philippe Brucker 0:1484ce3a8cdf 7 *
Jean-Philippe Brucker 0:1484ce3a8cdf 8 * http://www.apache.org/licenses/LICENSE-2.0
Jean-Philippe Brucker 0:1484ce3a8cdf 9 *
Jean-Philippe Brucker 0:1484ce3a8cdf 10 * Unless required by applicable law or agreed to in writing, software
Jean-Philippe Brucker 0:1484ce3a8cdf 11 * distributed under the License is distributed on an "AS IS" BASIS,
Jean-Philippe Brucker 0:1484ce3a8cdf 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Jean-Philippe Brucker 0:1484ce3a8cdf 13 * See the License for the specific language governing permissions and
Jean-Philippe Brucker 0:1484ce3a8cdf 14 * limitations under the License.
Jean-Philippe Brucker 0:1484ce3a8cdf 15 */
Jean-Philippe Brucker 0:1484ce3a8cdf 16
Jean-Philippe Brucker 0:1484ce3a8cdf 17 #include "ble/services/BatteryService.h"
Jean-Philippe Brucker 2:a0b9f9aa0e2d 18 #include "ble/services/DeviceInformationService.h"
Jean-Philippe Brucker 0:1484ce3a8cdf 19
Jean-Philippe Brucker 0:1484ce3a8cdf 20 #include "examples_common.h"
Jean-Philippe Brucker 0:1484ce3a8cdf 21
Jean-Philippe Brucker 0:1484ce3a8cdf 22 static void passkeyDisplayCallback(Gap::Handle_t handle, const SecurityManager::Passkey_t passkey)
Jean-Philippe Brucker 0:1484ce3a8cdf 23 {
Jean-Philippe Brucker 0:1484ce3a8cdf 24 printf("Input passKey: ");
Jean-Philippe Brucker 0:1484ce3a8cdf 25 for (unsigned i = 0; i < Gap::ADDR_LEN; i++) {
Jean-Philippe Brucker 0:1484ce3a8cdf 26 printf("%c", passkey[i]);
Jean-Philippe Brucker 0:1484ce3a8cdf 27 }
Jean-Philippe Brucker 0:1484ce3a8cdf 28 printf("\r\n");
Jean-Philippe Brucker 0:1484ce3a8cdf 29 }
Jean-Philippe Brucker 0:1484ce3a8cdf 30
Jean-Philippe Brucker 0:1484ce3a8cdf 31 static void securitySetupCompletedCallback(Gap::Handle_t handle, SecurityManager::SecurityCompletionStatus_t status)
Jean-Philippe Brucker 0:1484ce3a8cdf 32 {
Jean-Philippe Brucker 0:1484ce3a8cdf 33 if (status == SecurityManager::SEC_STATUS_SUCCESS) {
Jean-Philippe Brucker 0:1484ce3a8cdf 34 printf("Security success %d\r\n", status);
Jean-Philippe Brucker 0:1484ce3a8cdf 35 } else {
Jean-Philippe Brucker 0:1484ce3a8cdf 36 printf("Security failed %d\r\n", status);
Jean-Philippe Brucker 0:1484ce3a8cdf 37 }
Jean-Philippe Brucker 0:1484ce3a8cdf 38 }
Jean-Philippe Brucker 0:1484ce3a8cdf 39
Jean-Philippe Brucker 0:1484ce3a8cdf 40 static void securitySetupInitiatedCallback(Gap::Handle_t, bool allowBonding, bool requireMITM, SecurityManager::SecurityIOCapabilities_t iocaps)
Jean-Philippe Brucker 0:1484ce3a8cdf 41 {
Jean-Philippe Brucker 0:1484ce3a8cdf 42 printf("Security setup initiated\r\n");
Jean-Philippe Brucker 0:1484ce3a8cdf 43 }
Jean-Philippe Brucker 0:1484ce3a8cdf 44
Jean-Philippe Brucker 0:1484ce3a8cdf 45 void initializeSecurity(BLE &ble)
Jean-Philippe Brucker 0:1484ce3a8cdf 46 {
Jean-Philippe Brucker 0:1484ce3a8cdf 47 bool enableBonding = true;
Jean-Philippe Brucker 0:1484ce3a8cdf 48 bool requireMITM = HID_SECURITY_REQUIRE_MITM;
Jean-Philippe Brucker 0:1484ce3a8cdf 49
Jean-Philippe Brucker 0:1484ce3a8cdf 50 ble.securityManager().onSecuritySetupInitiated(securitySetupInitiatedCallback);
Jean-Philippe Brucker 0:1484ce3a8cdf 51 ble.securityManager().onPasskeyDisplay(passkeyDisplayCallback);
Jean-Philippe Brucker 0:1484ce3a8cdf 52 ble.securityManager().onSecuritySetupCompleted(securitySetupCompletedCallback);
Jean-Philippe Brucker 0:1484ce3a8cdf 53
Jean-Philippe Brucker 0:1484ce3a8cdf 54 ble.securityManager().init(enableBonding, requireMITM, HID_SECURITY_IOCAPS);
Jean-Philippe Brucker 0:1484ce3a8cdf 55 }
Jean-Philippe Brucker 0:1484ce3a8cdf 56
Jean-Philippe Brucker 0:1484ce3a8cdf 57 void initializeHOGP(BLE &ble)
Jean-Philippe Brucker 0:1484ce3a8cdf 58 {
Jean-Philippe Brucker 0:1484ce3a8cdf 59 static const uint16_t uuid16_list[] = {GattService::UUID_HUMAN_INTERFACE_DEVICE_SERVICE,
Jean-Philippe Brucker 0:1484ce3a8cdf 60 GattService::UUID_DEVICE_INFORMATION_SERVICE,
Jean-Philippe Brucker 0:1484ce3a8cdf 61 GattService::UUID_BATTERY_SERVICE};
Jean-Philippe Brucker 0:1484ce3a8cdf 62
Jean-Philippe Brucker 2:a0b9f9aa0e2d 63 DeviceInformationService deviceInfo(ble, "ARM", "m1", "abc", "def", "ghi", "jkl");
Jean-Philippe Brucker 0:1484ce3a8cdf 64
Jean-Philippe Brucker 0:1484ce3a8cdf 65 BatteryService batteryInfo(ble, 80);
Jean-Philippe Brucker 0:1484ce3a8cdf 66
Jean-Philippe Brucker 0:1484ce3a8cdf 67 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED |
Jean-Philippe Brucker 0:1484ce3a8cdf 68 GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
Jean-Philippe Brucker 0:1484ce3a8cdf 69 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,
Jean-Philippe Brucker 0:1484ce3a8cdf 70 (uint8_t *)uuid16_list, sizeof(uuid16_list));
Jean-Philippe Brucker 0:1484ce3a8cdf 71
Jean-Philippe Brucker 0:1484ce3a8cdf 72 // see 5.1.2: HID over GATT Specification (pg. 25)
Jean-Philippe Brucker 0:1484ce3a8cdf 73 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Jean-Philippe Brucker 0:1484ce3a8cdf 74 // 30ms to 50ms is recommended (5.1.2)
Jean-Philippe Brucker 0:1484ce3a8cdf 75 ble.gap().setAdvertisingInterval(50);
Jean-Philippe Brucker 0:1484ce3a8cdf 76 }