HID-over-GATT implementation with the BLE API. This library allows to create devices such as mouse, keyboard or joystick, over Bluetooth Low Energy.
Dependents: MtConnect04S_Gesture_HID
Fork of BLE_HID by
DeviceInformationService.h@5:dc4e6dbcb79b, 2017-01-17 (annotated)
- Committer:
- bcc6
- Date:
- Tue Jan 17 03:48:12 2017 +0000
- Revision:
- 5:dc4e6dbcb79b
Add PNP_ID in DeviceInformationService; Add bootKeyboardInputReportCharacteristic, bootKeyboardOutputReportCharacteristic in HIDServiceBase
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcc6 | 5:dc4e6dbcb79b | 1 | /* mbed Microcontroller Library |
bcc6 | 5:dc4e6dbcb79b | 2 | * Copyright (c) 2006-2013 ARM Limited |
bcc6 | 5:dc4e6dbcb79b | 3 | * |
bcc6 | 5:dc4e6dbcb79b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bcc6 | 5:dc4e6dbcb79b | 5 | * you may not use this file except in compliance with the License. |
bcc6 | 5:dc4e6dbcb79b | 6 | * You may obtain a copy of the License at |
bcc6 | 5:dc4e6dbcb79b | 7 | * |
bcc6 | 5:dc4e6dbcb79b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bcc6 | 5:dc4e6dbcb79b | 9 | * |
bcc6 | 5:dc4e6dbcb79b | 10 | * Unless required by applicable law or agreed to in writing, software |
bcc6 | 5:dc4e6dbcb79b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bcc6 | 5:dc4e6dbcb79b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bcc6 | 5:dc4e6dbcb79b | 13 | * See the License for the specific language governing permissions and |
bcc6 | 5:dc4e6dbcb79b | 14 | * limitations under the License. |
bcc6 | 5:dc4e6dbcb79b | 15 | */ |
bcc6 | 5:dc4e6dbcb79b | 16 | |
bcc6 | 5:dc4e6dbcb79b | 17 | #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__ |
bcc6 | 5:dc4e6dbcb79b | 18 | #define __BLE_DEVICE_INFORMATION_SERVICE_H__ |
bcc6 | 5:dc4e6dbcb79b | 19 | |
bcc6 | 5:dc4e6dbcb79b | 20 | #include "ble/BLE.h" |
bcc6 | 5:dc4e6dbcb79b | 21 | |
bcc6 | 5:dc4e6dbcb79b | 22 | |
bcc6 | 5:dc4e6dbcb79b | 23 | /* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.pnp_id.xml */ |
bcc6 | 5:dc4e6dbcb79b | 24 | #pragma pack(push, 1) |
bcc6 | 5:dc4e6dbcb79b | 25 | typedef struct { |
bcc6 | 5:dc4e6dbcb79b | 26 | uint8_t vendorID_source; |
bcc6 | 5:dc4e6dbcb79b | 27 | uint16_t vendorID; |
bcc6 | 5:dc4e6dbcb79b | 28 | uint16_t productID; |
bcc6 | 5:dc4e6dbcb79b | 29 | uint16_t productVersion; |
bcc6 | 5:dc4e6dbcb79b | 30 | } PnPID_t; |
bcc6 | 5:dc4e6dbcb79b | 31 | #pragma pack(pop) |
bcc6 | 5:dc4e6dbcb79b | 32 | |
bcc6 | 5:dc4e6dbcb79b | 33 | |
bcc6 | 5:dc4e6dbcb79b | 34 | /** |
bcc6 | 5:dc4e6dbcb79b | 35 | * @class DeviceInformationService |
bcc6 | 5:dc4e6dbcb79b | 36 | * @brief BLE Device Information Service |
bcc6 | 5:dc4e6dbcb79b | 37 | * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml |
bcc6 | 5:dc4e6dbcb79b | 38 | * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml |
bcc6 | 5:dc4e6dbcb79b | 39 | */ |
bcc6 | 5:dc4e6dbcb79b | 40 | class DeviceInformationService { |
bcc6 | 5:dc4e6dbcb79b | 41 | public: |
bcc6 | 5:dc4e6dbcb79b | 42 | /** |
bcc6 | 5:dc4e6dbcb79b | 43 | * @brief Device Information Service Constructor: copies device-specific information |
bcc6 | 5:dc4e6dbcb79b | 44 | * into the BLE stack. |
bcc6 | 5:dc4e6dbcb79b | 45 | * |
bcc6 | 5:dc4e6dbcb79b | 46 | * @param[in] _ble |
bcc6 | 5:dc4e6dbcb79b | 47 | * A reference to a BLE object for the underlying controller. |
bcc6 | 5:dc4e6dbcb79b | 48 | * @param[in] manufacturersName |
bcc6 | 5:dc4e6dbcb79b | 49 | * The name of the manufacturer of the device. |
bcc6 | 5:dc4e6dbcb79b | 50 | * @param[in] modelNumber |
bcc6 | 5:dc4e6dbcb79b | 51 | * The model number that is assigned by the device vendor. |
bcc6 | 5:dc4e6dbcb79b | 52 | * @param[in] serialNumber |
bcc6 | 5:dc4e6dbcb79b | 53 | * The serial number for a particular instance of the device. |
bcc6 | 5:dc4e6dbcb79b | 54 | * @param[in] hardwareRevision |
bcc6 | 5:dc4e6dbcb79b | 55 | * The hardware revision for the hardware within the device. |
bcc6 | 5:dc4e6dbcb79b | 56 | * @param[in] firmwareRevision |
bcc6 | 5:dc4e6dbcb79b | 57 | * The device's firmware version. |
bcc6 | 5:dc4e6dbcb79b | 58 | * @param[in] softwareRevision |
bcc6 | 5:dc4e6dbcb79b | 59 | * The device's software version. |
bcc6 | 5:dc4e6dbcb79b | 60 | * @param[in] pnpID |
bcc6 | 5:dc4e6dbcb79b | 61 | * vendor id, product id and version. |
bcc6 | 5:dc4e6dbcb79b | 62 | */ |
bcc6 | 5:dc4e6dbcb79b | 63 | DeviceInformationService(BLE &_ble, |
bcc6 | 5:dc4e6dbcb79b | 64 | const char *manufacturersName = NULL, |
bcc6 | 5:dc4e6dbcb79b | 65 | const char *modelNumber = NULL, |
bcc6 | 5:dc4e6dbcb79b | 66 | const char *serialNumber = NULL, |
bcc6 | 5:dc4e6dbcb79b | 67 | const char *hardwareRevision = NULL, |
bcc6 | 5:dc4e6dbcb79b | 68 | const char *firmwareRevision = NULL, |
bcc6 | 5:dc4e6dbcb79b | 69 | const char *softwareRevision = NULL, |
bcc6 | 5:dc4e6dbcb79b | 70 | PnPID_t *pnpID = NULL) : |
bcc6 | 5:dc4e6dbcb79b | 71 | ble(_ble), |
bcc6 | 5:dc4e6dbcb79b | 72 | manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, |
bcc6 | 5:dc4e6dbcb79b | 73 | (uint8_t *)manufacturersName, |
bcc6 | 5:dc4e6dbcb79b | 74 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Min length */ |
bcc6 | 5:dc4e6dbcb79b | 75 | (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Max length */ |
bcc6 | 5:dc4e6dbcb79b | 76 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
bcc6 | 5:dc4e6dbcb79b | 77 | modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, |
bcc6 | 5:dc4e6dbcb79b | 78 | (uint8_t *)modelNumber, |
bcc6 | 5:dc4e6dbcb79b | 79 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Min length */ |
bcc6 | 5:dc4e6dbcb79b | 80 | (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Max length */ |
bcc6 | 5:dc4e6dbcb79b | 81 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
bcc6 | 5:dc4e6dbcb79b | 82 | serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, |
bcc6 | 5:dc4e6dbcb79b | 83 | (uint8_t *)serialNumber, |
bcc6 | 5:dc4e6dbcb79b | 84 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Min length */ |
bcc6 | 5:dc4e6dbcb79b | 85 | (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Max length */ |
bcc6 | 5:dc4e6dbcb79b | 86 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
bcc6 | 5:dc4e6dbcb79b | 87 | hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, |
bcc6 | 5:dc4e6dbcb79b | 88 | (uint8_t *)hardwareRevision, |
bcc6 | 5:dc4e6dbcb79b | 89 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Min length */ |
bcc6 | 5:dc4e6dbcb79b | 90 | (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Max length */ |
bcc6 | 5:dc4e6dbcb79b | 91 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
bcc6 | 5:dc4e6dbcb79b | 92 | firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, |
bcc6 | 5:dc4e6dbcb79b | 93 | (uint8_t *)firmwareRevision, |
bcc6 | 5:dc4e6dbcb79b | 94 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Min length */ |
bcc6 | 5:dc4e6dbcb79b | 95 | (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Max length */ |
bcc6 | 5:dc4e6dbcb79b | 96 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
bcc6 | 5:dc4e6dbcb79b | 97 | softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, |
bcc6 | 5:dc4e6dbcb79b | 98 | (uint8_t *)softwareRevision, |
bcc6 | 5:dc4e6dbcb79b | 99 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Min length */ |
bcc6 | 5:dc4e6dbcb79b | 100 | (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Max length */ |
bcc6 | 5:dc4e6dbcb79b | 101 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), |
bcc6 | 5:dc4e6dbcb79b | 102 | pnpIDCharacteristic(GattCharacteristic::UUID_PNP_ID_CHAR, |
bcc6 | 5:dc4e6dbcb79b | 103 | pnpID) |
bcc6 | 5:dc4e6dbcb79b | 104 | { |
bcc6 | 5:dc4e6dbcb79b | 105 | static bool serviceAdded = false; /* We only add the information service once. */ |
bcc6 | 5:dc4e6dbcb79b | 106 | if (serviceAdded) { |
bcc6 | 5:dc4e6dbcb79b | 107 | return; |
bcc6 | 5:dc4e6dbcb79b | 108 | } |
bcc6 | 5:dc4e6dbcb79b | 109 | |
bcc6 | 5:dc4e6dbcb79b | 110 | /* required for OS X bonding */ |
bcc6 | 5:dc4e6dbcb79b | 111 | pnpIDCharacteristic.requireSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM); |
bcc6 | 5:dc4e6dbcb79b | 112 | |
bcc6 | 5:dc4e6dbcb79b | 113 | GattCharacteristic *charTable[] = {&manufacturersNameStringCharacteristic, |
bcc6 | 5:dc4e6dbcb79b | 114 | &modelNumberStringCharacteristic, |
bcc6 | 5:dc4e6dbcb79b | 115 | &serialNumberStringCharacteristic, |
bcc6 | 5:dc4e6dbcb79b | 116 | &hardwareRevisionStringCharacteristic, |
bcc6 | 5:dc4e6dbcb79b | 117 | &firmwareRevisionStringCharacteristic, |
bcc6 | 5:dc4e6dbcb79b | 118 | &softwareRevisionStringCharacteristic, |
bcc6 | 5:dc4e6dbcb79b | 119 | &pnpIDCharacteristic}; |
bcc6 | 5:dc4e6dbcb79b | 120 | GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, |
bcc6 | 5:dc4e6dbcb79b | 121 | sizeof(charTable) / sizeof(GattCharacteristic *)); |
bcc6 | 5:dc4e6dbcb79b | 122 | |
bcc6 | 5:dc4e6dbcb79b | 123 | ble.addService(deviceInformationService); |
bcc6 | 5:dc4e6dbcb79b | 124 | serviceAdded = true; |
bcc6 | 5:dc4e6dbcb79b | 125 | } |
bcc6 | 5:dc4e6dbcb79b | 126 | |
bcc6 | 5:dc4e6dbcb79b | 127 | protected: |
bcc6 | 5:dc4e6dbcb79b | 128 | /** |
bcc6 | 5:dc4e6dbcb79b | 129 | * A reference to the BLE instance object to which the services and |
bcc6 | 5:dc4e6dbcb79b | 130 | * characteristics will be added. |
bcc6 | 5:dc4e6dbcb79b | 131 | */ |
bcc6 | 5:dc4e6dbcb79b | 132 | BLE &ble; |
bcc6 | 5:dc4e6dbcb79b | 133 | /** |
bcc6 | 5:dc4e6dbcb79b | 134 | * BLE characterising to allow BLE peers access to the manufacturer's name. |
bcc6 | 5:dc4e6dbcb79b | 135 | */ |
bcc6 | 5:dc4e6dbcb79b | 136 | GattCharacteristic manufacturersNameStringCharacteristic; |
bcc6 | 5:dc4e6dbcb79b | 137 | /** |
bcc6 | 5:dc4e6dbcb79b | 138 | * BLE characterising to allow BLE peers access to the model number. |
bcc6 | 5:dc4e6dbcb79b | 139 | */ |
bcc6 | 5:dc4e6dbcb79b | 140 | GattCharacteristic modelNumberStringCharacteristic; |
bcc6 | 5:dc4e6dbcb79b | 141 | /** |
bcc6 | 5:dc4e6dbcb79b | 142 | * BLE characterising to allow BLE peers access to the serial number. |
bcc6 | 5:dc4e6dbcb79b | 143 | */ |
bcc6 | 5:dc4e6dbcb79b | 144 | GattCharacteristic serialNumberStringCharacteristic; |
bcc6 | 5:dc4e6dbcb79b | 145 | /** |
bcc6 | 5:dc4e6dbcb79b | 146 | * BLE characterising to allow BLE peers access to the hardware revision string. |
bcc6 | 5:dc4e6dbcb79b | 147 | */ |
bcc6 | 5:dc4e6dbcb79b | 148 | GattCharacteristic hardwareRevisionStringCharacteristic; |
bcc6 | 5:dc4e6dbcb79b | 149 | /** |
bcc6 | 5:dc4e6dbcb79b | 150 | * BLE characterising to allow BLE peers access to the firmware revision string. |
bcc6 | 5:dc4e6dbcb79b | 151 | */ |
bcc6 | 5:dc4e6dbcb79b | 152 | GattCharacteristic firmwareRevisionStringCharacteristic; |
bcc6 | 5:dc4e6dbcb79b | 153 | /** |
bcc6 | 5:dc4e6dbcb79b | 154 | * BLE characterising to allow BLE peers access to the software revision string. |
bcc6 | 5:dc4e6dbcb79b | 155 | */ |
bcc6 | 5:dc4e6dbcb79b | 156 | GattCharacteristic softwareRevisionStringCharacteristic; |
bcc6 | 5:dc4e6dbcb79b | 157 | /** |
bcc6 | 5:dc4e6dbcb79b | 158 | * BLE characterising to allow BLE peers access to the PnP ID. |
bcc6 | 5:dc4e6dbcb79b | 159 | */ |
bcc6 | 5:dc4e6dbcb79b | 160 | ReadOnlyGattCharacteristic<PnPID_t> pnpIDCharacteristic; |
bcc6 | 5:dc4e6dbcb79b | 161 | }; |
bcc6 | 5:dc4e6dbcb79b | 162 | |
bcc6 | 5:dc4e6dbcb79b | 163 | #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/ |
bcc6 | 5:dc4e6dbcb79b | 164 |