Mistake on this page?
Report an issue in GitHub or email us
DeviceInformationService.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2020 ARM Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__
20 #define __BLE_DEVICE_INFORMATION_SERVICE_H__
21 
22 #include "ble/BLE.h"
23 #include "ble/Gap.h"
24 #include "ble/GattServer.h"
25 
26 #if BLE_FEATURE_GATT_SERVER
27 
28 /**
29 * @class DeviceInformationService
30 * @brief BLE Device Information Service
31 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml
32 * Manufacturer Name String Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml
33 */
35 public:
36  /**
37  * @brief Device Information Service Constructor: copies device-specific information
38  * into the BLE stack.
39  *
40  * @param[in] _ble
41  * A reference to a BLE object for the underlying controller.
42  * @param[in] manufacturersName
43  * The name of the manufacturer of the device.
44  * @param[in] modelNumber
45  * The model number that is assigned by the device vendor.
46  * @param[in] serialNumber
47  * The serial number for a particular instance of the device.
48  * @param[in] hardwareRevision
49  * The hardware revision for the hardware within the device.
50  * @param[in] firmwareRevision
51  * The device's firmware version.
52  * @param[in] softwareRevision
53  * The device's software version.
54  */
56  const char *manufacturersName = nullptr,
57  const char *modelNumber = nullptr,
58  const char *serialNumber = nullptr,
59  const char *hardwareRevision = nullptr,
60  const char *firmwareRevision = nullptr,
61  const char *softwareRevision = nullptr) :
62  ble(_ble),
63  manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR,
64  (uint8_t *)manufacturersName,
65  (manufacturersName != nullptr) ? strlen(manufacturersName) : 0, /* Min length */
66  (manufacturersName != nullptr) ? strlen(manufacturersName) : 0, /* Max length */
67  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
68  modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR,
69  (uint8_t *)modelNumber,
70  (modelNumber != nullptr) ? strlen(modelNumber) : 0, /* Min length */
71  (modelNumber != nullptr) ? strlen(modelNumber) : 0, /* Max length */
72  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
73  serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR,
74  (uint8_t *)serialNumber,
75  (serialNumber != nullptr) ? strlen(serialNumber) : 0, /* Min length */
76  (serialNumber != nullptr) ? strlen(serialNumber) : 0, /* Max length */
77  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
78  hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR,
79  (uint8_t *)hardwareRevision,
80  (hardwareRevision != nullptr) ? strlen(hardwareRevision) : 0, /* Min length */
81  (hardwareRevision != nullptr) ? strlen(hardwareRevision) : 0, /* Max length */
82  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
83  firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR,
84  (uint8_t *)firmwareRevision,
85  (firmwareRevision != nullptr) ? strlen(firmwareRevision) : 0, /* Min length */
86  (firmwareRevision != nullptr) ? strlen(firmwareRevision) : 0, /* Max length */
87  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
88  softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR,
89  (uint8_t *)softwareRevision,
90  (softwareRevision != nullptr) ? strlen(softwareRevision) : 0, /* Min length */
91  (softwareRevision != nullptr) ? strlen(softwareRevision) : 0, /* Max length */
92  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
93  {
94  static bool serviceAdded = false; /* We only add the information service once. */
95  if (serviceAdded) {
96  return;
97  }
98 
105  GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable,
106  sizeof(charTable) / sizeof(charTable[0]));
107 
108  ble.gattServer().addService(deviceInformationService);
109  serviceAdded = true;
110  }
111 
112 protected:
113  /**
114  * A reference to the BLE instance object to which the services and
115  * characteristics will be added.
116  */
118  /**
119  * BLE characterising to allow BLE peers access to the manufacturer's name.
120  */
122  /**
123  * BLE characterising to allow BLE peers access to the model number.
124  */
126  /**
127  * BLE characterising to allow BLE peers access to the serial number.
128  */
130  /**
131  * BLE characterising to allow BLE peers access to the hardware revision string.
132  */
134  /**
135  * BLE characterising to allow BLE peers access to the firmware revision string.
136  */
138  /**
139  * BLE characterising to allow BLE peers access to the software revision string.
140  */
142 };
143 
144 #endif // BLE_FEATURE_GATT_SERVER
145 
146 #endif /* #ifndef __BLE_DEVICE_INFORMATION_SERVICE_H__*/
UUID of the Device Information Service (DIS).
GattCharacteristic softwareRevisionStringCharacteristic
BLE characterising to allow BLE peers access to the software revision string.
GattCharacteristic modelNumberStringCharacteristic
BLE characterising to allow BLE peers access to the model number.
GattCharacteristic serialNumberStringCharacteristic
BLE characterising to allow BLE peers access to the serial number.
GattCharacteristic manufacturersNameStringCharacteristic
BLE characterising to allow BLE peers access to the manufacturer's name.
BLE Device Information Service Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceVi...
DeviceInformationService(BLE &_ble, const char *manufacturersName=nullptr, const char *modelNumber=nullptr, const char *serialNumber=nullptr, const char *hardwareRevision=nullptr, const char *firmwareRevision=nullptr, const char *softwareRevision=nullptr)
Device Information Service Constructor: copies device-specific information into the BLE stack...
Representation of a GattServer characteristic.
GattCharacteristic hardwareRevisionStringCharacteristic
BLE characterising to allow BLE peers access to the hardware revision string.
Representation of a GattServer service.
GattCharacteristic firmwareRevisionStringCharacteristic
BLE characterising to allow BLE peers access to the firmware revision string.
Entry namespace for all BLE API definitions.
Abstract away BLE-capable radio transceivers or SOCs.
Definition: BLE.h:137
BLE & ble
A reference to the BLE instance object to which the services and characteristics will be added...
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.