Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MrBedfordVan 0:b9164b348919 1 /* mbed Microcontroller Library
MrBedfordVan 0:b9164b348919 2 * Copyright (c) 2006-2013 ARM Limited
MrBedfordVan 0:b9164b348919 3 *
MrBedfordVan 0:b9164b348919 4 * Licensed under the Apache License, Version 2.0 (the "License");
MrBedfordVan 0:b9164b348919 5 * you may not use this file except in compliance with the License.
MrBedfordVan 0:b9164b348919 6 * You may obtain a copy of the License at
MrBedfordVan 0:b9164b348919 7 *
MrBedfordVan 0:b9164b348919 8 * http://www.apache.org/licenses/LICENSE-2.0
MrBedfordVan 0:b9164b348919 9 *
MrBedfordVan 0:b9164b348919 10 * Unless required by applicable law or agreed to in writing, software
MrBedfordVan 0:b9164b348919 11 * distributed under the License is distributed on an "AS IS" BASIS,
MrBedfordVan 0:b9164b348919 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MrBedfordVan 0:b9164b348919 13 * See the License for the specific language governing permissions and
MrBedfordVan 0:b9164b348919 14 * limitations under the License.
MrBedfordVan 0:b9164b348919 15 */
MrBedfordVan 0:b9164b348919 16
MrBedfordVan 0:b9164b348919 17 #ifndef __GATT_CHARACTERISTIC_H__
MrBedfordVan 0:b9164b348919 18 #define __GATT_CHARACTERISTIC_H__
MrBedfordVan 0:b9164b348919 19
MrBedfordVan 0:b9164b348919 20 #include "Gap.h"
MrBedfordVan 0:b9164b348919 21 #include "SecurityManager.h"
MrBedfordVan 0:b9164b348919 22 #include "GattAttribute.h"
MrBedfordVan 0:b9164b348919 23 #include "GattCallbackParamTypes.h"
MrBedfordVan 0:b9164b348919 24 #include "FunctionPointerWithContext.h"
MrBedfordVan 0:b9164b348919 25
MrBedfordVan 0:b9164b348919 26 class GattCharacteristic {
MrBedfordVan 0:b9164b348919 27 public:
MrBedfordVan 0:b9164b348919 28 enum {
MrBedfordVan 0:b9164b348919 29 UUID_BATTERY_LEVEL_STATE_CHAR = 0x2A1B,
MrBedfordVan 0:b9164b348919 30 UUID_BATTERY_POWER_STATE_CHAR = 0x2A1A,
MrBedfordVan 0:b9164b348919 31 UUID_REMOVABLE_CHAR = 0x2A3A,
MrBedfordVan 0:b9164b348919 32 UUID_SERVICE_REQUIRED_CHAR = 0x2A3B,
MrBedfordVan 0:b9164b348919 33 UUID_ALERT_CATEGORY_ID_CHAR = 0x2A43,
MrBedfordVan 0:b9164b348919 34 UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR = 0x2A42,
MrBedfordVan 0:b9164b348919 35 UUID_ALERT_LEVEL_CHAR = 0x2A06,
MrBedfordVan 0:b9164b348919 36 UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR = 0x2A44,
MrBedfordVan 0:b9164b348919 37 UUID_ALERT_STATUS_CHAR = 0x2A3F,
MrBedfordVan 0:b9164b348919 38 UUID_BATTERY_LEVEL_CHAR = 0x2A19,
MrBedfordVan 0:b9164b348919 39 UUID_BLOOD_PRESSURE_FEATURE_CHAR = 0x2A49,
MrBedfordVan 0:b9164b348919 40 UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR = 0x2A35,
MrBedfordVan 0:b9164b348919 41 UUID_BODY_SENSOR_LOCATION_CHAR = 0x2A38,
MrBedfordVan 0:b9164b348919 42 UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR = 0x2A22,
MrBedfordVan 0:b9164b348919 43 UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR = 0x2A32,
MrBedfordVan 0:b9164b348919 44 UUID_BOOT_MOUSE_INPUT_REPORT_CHAR = 0x2A33,
MrBedfordVan 0:b9164b348919 45 UUID_CURRENT_TIME_CHAR = 0x2A2B,
MrBedfordVan 0:b9164b348919 46 UUID_DATE_TIME_CHAR = 0x2A08,
MrBedfordVan 0:b9164b348919 47 UUID_DAY_DATE_TIME_CHAR = 0x2A0A,
MrBedfordVan 0:b9164b348919 48 UUID_DAY_OF_WEEK_CHAR = 0x2A09,
MrBedfordVan 0:b9164b348919 49 UUID_DST_OFFSET_CHAR = 0x2A0D,
MrBedfordVan 0:b9164b348919 50 UUID_EXACT_TIME_256_CHAR = 0x2A0C,
MrBedfordVan 0:b9164b348919 51 UUID_FIRMWARE_REVISION_STRING_CHAR = 0x2A26,
MrBedfordVan 0:b9164b348919 52 UUID_GLUCOSE_FEATURE_CHAR = 0x2A51,
MrBedfordVan 0:b9164b348919 53 UUID_GLUCOSE_MEASUREMENT_CHAR = 0x2A18,
MrBedfordVan 0:b9164b348919 54 UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR = 0x2A34,
MrBedfordVan 0:b9164b348919 55 UUID_HARDWARE_REVISION_STRING_CHAR = 0x2A27,
MrBedfordVan 0:b9164b348919 56 UUID_HEART_RATE_CONTROL_POINT_CHAR = 0x2A39,
MrBedfordVan 0:b9164b348919 57 UUID_HEART_RATE_MEASUREMENT_CHAR = 0x2A37,
MrBedfordVan 0:b9164b348919 58 UUID_HID_CONTROL_POINT_CHAR = 0x2A4C,
MrBedfordVan 0:b9164b348919 59 UUID_HID_INFORMATION_CHAR = 0x2A4A,
MrBedfordVan 0:b9164b348919 60 UUID_HUMIDITY_CHAR = 0x2A6F,
MrBedfordVan 0:b9164b348919 61 UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR = 0x2A2A,
MrBedfordVan 0:b9164b348919 62 UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR = 0x2A36,
MrBedfordVan 0:b9164b348919 63 UUID_INTERMEDIATE_TEMPERATURE_CHAR = 0x2A1E,
MrBedfordVan 0:b9164b348919 64 UUID_LOCAL_TIME_INFORMATION_CHAR = 0x2A0F,
MrBedfordVan 0:b9164b348919 65 UUID_MANUFACTURER_NAME_STRING_CHAR = 0x2A29,
MrBedfordVan 0:b9164b348919 66 UUID_MEASUREMENT_INTERVAL_CHAR = 0x2A21,
MrBedfordVan 0:b9164b348919 67 UUID_MODEL_NUMBER_STRING_CHAR = 0x2A24,
MrBedfordVan 0:b9164b348919 68 UUID_UNREAD_ALERT_CHAR = 0x2A45,
MrBedfordVan 0:b9164b348919 69 UUID_NEW_ALERT_CHAR = 0x2A46,
MrBedfordVan 0:b9164b348919 70 UUID_PNP_ID_CHAR = 0x2A50,
MrBedfordVan 0:b9164b348919 71 UUID_PRESSURE_CHAR = 0x2A6D,
MrBedfordVan 0:b9164b348919 72 UUID_PROTOCOL_MODE_CHAR = 0x2A4E,
MrBedfordVan 0:b9164b348919 73 UUID_RECORD_ACCESS_CONTROL_POINT_CHAR = 0x2A52,
MrBedfordVan 0:b9164b348919 74 UUID_REFERENCE_TIME_INFORMATION_CHAR = 0x2A14,
MrBedfordVan 0:b9164b348919 75 UUID_REPORT_CHAR = 0x2A4D,
MrBedfordVan 0:b9164b348919 76 UUID_REPORT_MAP_CHAR = 0x2A4B,
MrBedfordVan 0:b9164b348919 77 UUID_RINGER_CONTROL_POINT_CHAR = 0x2A40,
MrBedfordVan 0:b9164b348919 78 UUID_RINGER_SETTING_CHAR = 0x2A41,
MrBedfordVan 0:b9164b348919 79 UUID_SCAN_INTERVAL_WINDOW_CHAR = 0x2A4F,
MrBedfordVan 0:b9164b348919 80 UUID_SCAN_REFRESH_CHAR = 0x2A31,
MrBedfordVan 0:b9164b348919 81 UUID_SERIAL_NUMBER_STRING_CHAR = 0x2A25,
MrBedfordVan 0:b9164b348919 82 UUID_SOFTWARE_REVISION_STRING_CHAR = 0x2A28,
MrBedfordVan 0:b9164b348919 83 UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR = 0x2A47,
MrBedfordVan 0:b9164b348919 84 UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR = 0x2A48,
MrBedfordVan 0:b9164b348919 85 UUID_SYSTEM_ID_CHAR = 0x2A23,
MrBedfordVan 0:b9164b348919 86 UUID_TEMPERATURE_CHAR = 0x2A6E,
MrBedfordVan 0:b9164b348919 87 UUID_TEMPERATURE_MEASUREMENT_CHAR = 0x2A1C,
MrBedfordVan 0:b9164b348919 88 UUID_TEMPERATURE_TYPE_CHAR = 0x2A1D,
MrBedfordVan 0:b9164b348919 89 UUID_TIME_ACCURACY_CHAR = 0x2A12,
MrBedfordVan 0:b9164b348919 90 UUID_TIME_SOURCE_CHAR = 0x2A13,
MrBedfordVan 0:b9164b348919 91 UUID_TIME_UPDATE_CONTROL_POINT_CHAR = 0x2A16,
MrBedfordVan 0:b9164b348919 92 UUID_TIME_UPDATE_STATE_CHAR = 0x2A17,
MrBedfordVan 0:b9164b348919 93 UUID_TIME_WITH_DST_CHAR = 0x2A11,
MrBedfordVan 0:b9164b348919 94 UUID_TIME_ZONE_CHAR = 0x2A0E,
MrBedfordVan 0:b9164b348919 95 UUID_TX_POWER_LEVEL_CHAR = 0x2A07,
MrBedfordVan 0:b9164b348919 96 UUID_CSC_FEATURE_CHAR = 0x2A5C,
MrBedfordVan 0:b9164b348919 97 UUID_CSC_MEASUREMENT_CHAR = 0x2A5B,
MrBedfordVan 0:b9164b348919 98 UUID_RSC_FEATURE_CHAR = 0x2A54,
MrBedfordVan 0:b9164b348919 99 UUID_RSC_MEASUREMENT_CHAR = 0x2A53
MrBedfordVan 0:b9164b348919 100 };
MrBedfordVan 0:b9164b348919 101
MrBedfordVan 0:b9164b348919 102 /**************************************************************************/
MrBedfordVan 0:b9164b348919 103 /*!
MrBedfordVan 0:b9164b348919 104 \brief Standard GATT characteristic presentation format unit types.
MrBedfordVan 0:b9164b348919 105 These unit types are used to describe what the raw numeric
MrBedfordVan 0:b9164b348919 106 data in a characteristic actually represents.
MrBedfordVan 0:b9164b348919 107
MrBedfordVan 0:b9164b348919 108 \note See https://developer.bluetooth.org/gatt/units/Pages/default.aspx
MrBedfordVan 0:b9164b348919 109 */
MrBedfordVan 0:b9164b348919 110 /**************************************************************************/
MrBedfordVan 0:b9164b348919 111 enum {
MrBedfordVan 0:b9164b348919 112 BLE_GATT_UNIT_NONE = 0x2700, /**< No specified unit type. */
MrBedfordVan 0:b9164b348919 113 BLE_GATT_UNIT_LENGTH_METRE = 0x2701, /**< Length, metre. */
MrBedfordVan 0:b9164b348919 114 BLE_GATT_UNIT_MASS_KILOGRAM = 0x2702, /**< Mass, kilogram. */
MrBedfordVan 0:b9164b348919 115 BLE_GATT_UNIT_TIME_SECOND = 0x2703, /**< Time, second. */
MrBedfordVan 0:b9164b348919 116 BLE_GATT_UNIT_ELECTRIC_CURRENT_AMPERE = 0x2704, /**< Electric current, ampere. */
MrBedfordVan 0:b9164b348919 117 BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_KELVIN = 0x2705, /**< Thermodynamic temperature, kelvin. */
MrBedfordVan 0:b9164b348919 118 BLE_GATT_UNIT_AMOUNT_OF_SUBSTANCE_MOLE = 0x2706, /**< Amount of substance, mole. */
MrBedfordVan 0:b9164b348919 119 BLE_GATT_UNIT_LUMINOUS_INTENSITY_CANDELA = 0x2707, /**< Luminous intensity, candela. */
MrBedfordVan 0:b9164b348919 120 BLE_GATT_UNIT_AREA_SQUARE_METRES = 0x2710, /**< Area, square metres. */
MrBedfordVan 0:b9164b348919 121 BLE_GATT_UNIT_VOLUME_CUBIC_METRES = 0x2711, /**< Volume, cubic metres. */
MrBedfordVan 0:b9164b348919 122 BLE_GATT_UNIT_VELOCITY_METRES_PER_SECOND = 0x2712, /**< Velocity, metres per second. */
MrBedfordVan 0:b9164b348919 123 BLE_GATT_UNIT_ACCELERATION_METRES_PER_SECOND_SQUARED = 0x2713, /**< Acceleration, metres per second squared. */
MrBedfordVan 0:b9164b348919 124 BLE_GATT_UNIT_WAVENUMBER_RECIPROCAL_METRE = 0x2714, /**< Wave number reciprocal, metre. */
MrBedfordVan 0:b9164b348919 125 BLE_GATT_UNIT_DENSITY_KILOGRAM_PER_CUBIC_METRE = 0x2715, /**< Density, kilogram per cubic metre. */
MrBedfordVan 0:b9164b348919 126 BLE_GATT_UNIT_SURFACE_DENSITY_KILOGRAM_PER_SQUARE_METRE = 0x2716, /**< */
MrBedfordVan 0:b9164b348919 127 BLE_GATT_UNIT_SPECIFIC_VOLUME_CUBIC_METRE_PER_KILOGRAM = 0x2717, /**< */
MrBedfordVan 0:b9164b348919 128 BLE_GATT_UNIT_CURRENT_DENSITY_AMPERE_PER_SQUARE_METRE = 0x2718, /**< */
MrBedfordVan 0:b9164b348919 129 BLE_GATT_UNIT_MAGNETIC_FIELD_STRENGTH_AMPERE_PER_METRE = 0x2719, /**< Magnetic field strength, ampere per metre. */
MrBedfordVan 0:b9164b348919 130 BLE_GATT_UNIT_AMOUNT_CONCENTRATION_MOLE_PER_CUBIC_METRE = 0x271A, /**< */
MrBedfordVan 0:b9164b348919 131 BLE_GATT_UNIT_MASS_CONCENTRATION_KILOGRAM_PER_CUBIC_METRE = 0x271B, /**< */
MrBedfordVan 0:b9164b348919 132 BLE_GATT_UNIT_LUMINANCE_CANDELA_PER_SQUARE_METRE = 0x271C, /**< */
MrBedfordVan 0:b9164b348919 133 BLE_GATT_UNIT_REFRACTIVE_INDEX = 0x271D, /**< */
MrBedfordVan 0:b9164b348919 134 BLE_GATT_UNIT_RELATIVE_PERMEABILITY = 0x271E, /**< */
MrBedfordVan 0:b9164b348919 135 BLE_GATT_UNIT_PLANE_ANGLE_RADIAN = 0x2720, /**< */
MrBedfordVan 0:b9164b348919 136 BLE_GATT_UNIT_SOLID_ANGLE_STERADIAN = 0x2721, /**< */
MrBedfordVan 0:b9164b348919 137 BLE_GATT_UNIT_FREQUENCY_HERTZ = 0x2722, /**< Frequency, hertz. */
MrBedfordVan 0:b9164b348919 138 BLE_GATT_UNIT_FORCE_NEWTON = 0x2723, /**< Force, newton. */
MrBedfordVan 0:b9164b348919 139 BLE_GATT_UNIT_PRESSURE_PASCAL = 0x2724, /**< Pressure, pascal. */
MrBedfordVan 0:b9164b348919 140 BLE_GATT_UNIT_ENERGY_JOULE = 0x2725, /**< Energy, joule. */
MrBedfordVan 0:b9164b348919 141 BLE_GATT_UNIT_POWER_WATT = 0x2726, /**< Power, watt. */
MrBedfordVan 0:b9164b348919 142 BLE_GATT_UNIT_ELECTRIC_CHARGE_COULOMB = 0x2727, /**< Electrical charge, coulomb. */
MrBedfordVan 0:b9164b348919 143 BLE_GATT_UNIT_ELECTRIC_POTENTIAL_DIFFERENCE_VOLT = 0x2728, /**< Electrical potential difference, voltage. */
MrBedfordVan 0:b9164b348919 144 BLE_GATT_UNIT_CAPACITANCE_FARAD = 0x2729, /**< */
MrBedfordVan 0:b9164b348919 145 BLE_GATT_UNIT_ELECTRIC_RESISTANCE_OHM = 0x272A, /**< */
MrBedfordVan 0:b9164b348919 146 BLE_GATT_UNIT_ELECTRIC_CONDUCTANCE_SIEMENS = 0x272B, /**< */
MrBedfordVan 0:b9164b348919 147 BLE_GATT_UNIT_MAGNETIC_FLEX_WEBER = 0x272C, /**< */
MrBedfordVan 0:b9164b348919 148 BLE_GATT_UNIT_MAGNETIC_FLEX_DENSITY_TESLA = 0x272D, /**< */
MrBedfordVan 0:b9164b348919 149 BLE_GATT_UNIT_INDUCTANCE_HENRY = 0x272E, /**< */
MrBedfordVan 0:b9164b348919 150 BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_CELSIUS = 0x272F, /**< */
MrBedfordVan 0:b9164b348919 151 BLE_GATT_UNIT_LUMINOUS_FLUX_LUMEN = 0x2730, /**< */
MrBedfordVan 0:b9164b348919 152 BLE_GATT_UNIT_ILLUMINANCE_LUX = 0x2731, /**< */
MrBedfordVan 0:b9164b348919 153 BLE_GATT_UNIT_ACTIVITY_REFERRED_TO_A_RADIONUCLIDE_BECQUEREL = 0x2732, /**< */
MrBedfordVan 0:b9164b348919 154 BLE_GATT_UNIT_ABSORBED_DOSE_GRAY = 0x2733, /**< */
MrBedfordVan 0:b9164b348919 155 BLE_GATT_UNIT_DOSE_EQUIVALENT_SIEVERT = 0x2734, /**< */
MrBedfordVan 0:b9164b348919 156 BLE_GATT_UNIT_CATALYTIC_ACTIVITY_KATAL = 0x2735, /**< */
MrBedfordVan 0:b9164b348919 157 BLE_GATT_UNIT_DYNAMIC_VISCOSITY_PASCAL_SECOND = 0x2740, /**< */
MrBedfordVan 0:b9164b348919 158 BLE_GATT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE = 0x2741, /**< */
MrBedfordVan 0:b9164b348919 159 BLE_GATT_UNIT_SURFACE_TENSION_NEWTON_PER_METRE = 0x2742, /**< */
MrBedfordVan 0:b9164b348919 160 BLE_GATT_UNIT_ANGULAR_VELOCITY_RADIAN_PER_SECOND = 0x2743, /**< */
MrBedfordVan 0:b9164b348919 161 BLE_GATT_UNIT_ANGULAR_ACCELERATION_RADIAN_PER_SECOND_SQUARED = 0x2744, /**< */
MrBedfordVan 0:b9164b348919 162 BLE_GATT_UNIT_HEAT_FLUX_DENSITY_WATT_PER_SQUARE_METRE = 0x2745, /**< */
MrBedfordVan 0:b9164b348919 163 BLE_GATT_UNIT_HEAT_CAPACITY_JOULE_PER_KELVIN = 0x2746, /**< */
MrBedfordVan 0:b9164b348919 164 BLE_GATT_UNIT_SPECIFIC_HEAT_CAPACITY_JOULE_PER_KILOGRAM_KELVIN = 0x2747, /**< */
MrBedfordVan 0:b9164b348919 165 BLE_GATT_UNIT_SPECIFIC_ENERGY_JOULE_PER_KILOGRAM = 0x2748, /**< */
MrBedfordVan 0:b9164b348919 166 BLE_GATT_UNIT_THERMAL_CONDUCTIVITY_WATT_PER_METRE_KELVIN = 0x2749, /**< */
MrBedfordVan 0:b9164b348919 167 BLE_GATT_UNIT_ENERGY_DENSITY_JOULE_PER_CUBIC_METRE = 0x274A, /**< */
MrBedfordVan 0:b9164b348919 168 BLE_GATT_UNIT_ELECTRIC_FIELD_STRENGTH_VOLT_PER_METRE = 0x274B, /**< */
MrBedfordVan 0:b9164b348919 169 BLE_GATT_UNIT_ELECTRIC_CHARGE_DENSITY_COULOMB_PER_CUBIC_METRE = 0x274C, /**< */
MrBedfordVan 0:b9164b348919 170 BLE_GATT_UNIT_SURFACE_CHARGE_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274D, /**< */
MrBedfordVan 0:b9164b348919 171 BLE_GATT_UNIT_ELECTRIC_FLUX_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274E, /**< */
MrBedfordVan 0:b9164b348919 172 BLE_GATT_UNIT_PERMITTIVITY_FARAD_PER_METRE = 0x274F, /**< */
MrBedfordVan 0:b9164b348919 173 BLE_GATT_UNIT_PERMEABILITY_HENRY_PER_METRE = 0x2750, /**< */
MrBedfordVan 0:b9164b348919 174 BLE_GATT_UNIT_MOLAR_ENERGY_JOULE_PER_MOLE = 0x2751, /**< */
MrBedfordVan 0:b9164b348919 175 BLE_GATT_UNIT_MOLAR_ENTROPY_JOULE_PER_MOLE_KELVIN = 0x2752, /**< */
MrBedfordVan 0:b9164b348919 176 BLE_GATT_UNIT_EXPOSURE_COULOMB_PER_KILOGRAM = 0x2753, /**< */
MrBedfordVan 0:b9164b348919 177 BLE_GATT_UNIT_ABSORBED_DOSE_RATE_GRAY_PER_SECOND = 0x2754, /**< */
MrBedfordVan 0:b9164b348919 178 BLE_GATT_UNIT_RADIANT_INTENSITY_WATT_PER_STERADIAN = 0x2755, /**< */
MrBedfordVan 0:b9164b348919 179 BLE_GATT_UNIT_RADIANCE_WATT_PER_SQUARE_METRE_STERADIAN = 0x2756, /**< */
MrBedfordVan 0:b9164b348919 180 BLE_GATT_UNIT_CATALYTIC_ACTIVITY_CONCENTRATION_KATAL_PER_CUBIC_METRE = 0x2757, /**< */
MrBedfordVan 0:b9164b348919 181 BLE_GATT_UNIT_TIME_MINUTE = 0x2760, /**< Time, minute. */
MrBedfordVan 0:b9164b348919 182 BLE_GATT_UNIT_TIME_HOUR = 0x2761, /**< Time, hour. */
MrBedfordVan 0:b9164b348919 183 BLE_GATT_UNIT_TIME_DAY = 0x2762, /**< Time, day. */
MrBedfordVan 0:b9164b348919 184 BLE_GATT_UNIT_PLANE_ANGLE_DEGREE = 0x2763, /**< */
MrBedfordVan 0:b9164b348919 185 BLE_GATT_UNIT_PLANE_ANGLE_MINUTE = 0x2764, /**< */
MrBedfordVan 0:b9164b348919 186 BLE_GATT_UNIT_PLANE_ANGLE_SECOND = 0x2765, /**< */
MrBedfordVan 0:b9164b348919 187 BLE_GATT_UNIT_AREA_HECTARE = 0x2766, /**< */
MrBedfordVan 0:b9164b348919 188 BLE_GATT_UNIT_VOLUME_LITRE = 0x2767, /**< */
MrBedfordVan 0:b9164b348919 189 BLE_GATT_UNIT_MASS_TONNE = 0x2768, /**< */
MrBedfordVan 0:b9164b348919 190 BLE_GATT_UNIT_PRESSURE_BAR = 0x2780, /**< Pressure, bar. */
MrBedfordVan 0:b9164b348919 191 BLE_GATT_UNIT_PRESSURE_MILLIMETRE_OF_MERCURY = 0x2781, /**< Pressure, millimetre of mercury. */
MrBedfordVan 0:b9164b348919 192 BLE_GATT_UNIT_LENGTH_ANGSTROM = 0x2782, /**< */
MrBedfordVan 0:b9164b348919 193 BLE_GATT_UNIT_LENGTH_NAUTICAL_MILE = 0x2783, /**< */
MrBedfordVan 0:b9164b348919 194 BLE_GATT_UNIT_AREA_BARN = 0x2784, /**< */
MrBedfordVan 0:b9164b348919 195 BLE_GATT_UNIT_VELOCITY_KNOT = 0x2785, /**< */
MrBedfordVan 0:b9164b348919 196 BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_NEPER = 0x2786, /**< */
MrBedfordVan 0:b9164b348919 197 BLE_GATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_BEL = 0x2787, /**< */
MrBedfordVan 0:b9164b348919 198 BLE_GATT_UNIT_LENGTH_YARD = 0x27A0, /**< Length, yard. */
MrBedfordVan 0:b9164b348919 199 BLE_GATT_UNIT_LENGTH_PARSEC = 0x27A1, /**< Length, parsec. */
MrBedfordVan 0:b9164b348919 200 BLE_GATT_UNIT_LENGTH_INCH = 0x27A2, /**< Length, inch. */
MrBedfordVan 0:b9164b348919 201 BLE_GATT_UNIT_LENGTH_FOOT = 0x27A3, /**< Length, foot. */
MrBedfordVan 0:b9164b348919 202 BLE_GATT_UNIT_LENGTH_MILE = 0x27A4, /**< Length, mile. */
MrBedfordVan 0:b9164b348919 203 BLE_GATT_UNIT_PRESSURE_POUND_FORCE_PER_SQUARE_INCH = 0x27A5, /**< */
MrBedfordVan 0:b9164b348919 204 BLE_GATT_UNIT_VELOCITY_KILOMETRE_PER_HOUR = 0x27A6, /**< Velocity, kilometre per hour. */
MrBedfordVan 0:b9164b348919 205 BLE_GATT_UNIT_VELOCITY_MILE_PER_HOUR = 0x27A7, /**< Velocity, mile per hour. */
MrBedfordVan 0:b9164b348919 206 BLE_GATT_UNIT_ANGULAR_VELOCITY_REVOLUTION_PER_MINUTE = 0x27A8, /**< Angular Velocity, revolution per minute. */
MrBedfordVan 0:b9164b348919 207 BLE_GATT_UNIT_ENERGY_GRAM_CALORIE = 0x27A9, /**< Energy, gram calorie. */
MrBedfordVan 0:b9164b348919 208 BLE_GATT_UNIT_ENERGY_KILOGRAM_CALORIE = 0x27AA, /**< Energy, kilogram calorie. */
MrBedfordVan 0:b9164b348919 209 BLE_GATT_UNIT_ENERGY_KILOWATT_HOUR = 0x27AB, /**< Energy, killowatt hour. */
MrBedfordVan 0:b9164b348919 210 BLE_GATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_FAHRENHEIT = 0x27AC, /**< */
MrBedfordVan 0:b9164b348919 211 BLE_GATT_UNIT_PERCENTAGE = 0x27AD, /**< Percentage. */
MrBedfordVan 0:b9164b348919 212 BLE_GATT_UNIT_PER_MILLE = 0x27AE, /**< */
MrBedfordVan 0:b9164b348919 213 BLE_GATT_UNIT_PERIOD_BEATS_PER_MINUTE = 0x27AF, /**< */
MrBedfordVan 0:b9164b348919 214 BLE_GATT_UNIT_ELECTRIC_CHARGE_AMPERE_HOURS = 0x27B0, /**< */
MrBedfordVan 0:b9164b348919 215 BLE_GATT_UNIT_MASS_DENSITY_MILLIGRAM_PER_DECILITRE = 0x27B1, /**< */
MrBedfordVan 0:b9164b348919 216 BLE_GATT_UNIT_MASS_DENSITY_MILLIMOLE_PER_LITRE = 0x27B2, /**< */
MrBedfordVan 0:b9164b348919 217 BLE_GATT_UNIT_TIME_YEAR = 0x27B3, /**< Time, year. */
MrBedfordVan 0:b9164b348919 218 BLE_GATT_UNIT_TIME_MONTH = 0x27B4, /**< Time, month. */
MrBedfordVan 0:b9164b348919 219 BLE_GATT_UNIT_CONCENTRATION_COUNT_PER_CUBIC_METRE = 0x27B5, /**< */
MrBedfordVan 0:b9164b348919 220 BLE_GATT_UNIT_IRRADIANCE_WATT_PER_SQUARE_METRE = 0x27B6 /**< */
MrBedfordVan 0:b9164b348919 221 };
MrBedfordVan 0:b9164b348919 222
MrBedfordVan 0:b9164b348919 223 /**************************************************************************/
MrBedfordVan 0:b9164b348919 224 /*!
MrBedfordVan 0:b9164b348919 225 \brief Standard GATT number types.
MrBedfordVan 0:b9164b348919 226
MrBedfordVan 0:b9164b348919 227 \note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5.2
MrBedfordVan 0:b9164b348919 228 \note See http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
MrBedfordVan 0:b9164b348919 229 */
MrBedfordVan 0:b9164b348919 230 /**************************************************************************/
MrBedfordVan 0:b9164b348919 231 enum {
MrBedfordVan 0:b9164b348919 232 BLE_GATT_FORMAT_RFU = 0x00, /**< Reserved for future use. */
MrBedfordVan 0:b9164b348919 233 BLE_GATT_FORMAT_BOOLEAN = 0x01, /**< Boolean. */
MrBedfordVan 0:b9164b348919 234 BLE_GATT_FORMAT_2BIT = 0x02, /**< Unsigned 2-bit integer. */
MrBedfordVan 0:b9164b348919 235 BLE_GATT_FORMAT_NIBBLE = 0x03, /**< Unsigned 4-bit integer. */
MrBedfordVan 0:b9164b348919 236 BLE_GATT_FORMAT_UINT8 = 0x04, /**< Unsigned 8-bit integer. */
MrBedfordVan 0:b9164b348919 237 BLE_GATT_FORMAT_UINT12 = 0x05, /**< Unsigned 12-bit integer. */
MrBedfordVan 0:b9164b348919 238 BLE_GATT_FORMAT_UINT16 = 0x06, /**< Unsigned 16-bit integer. */
MrBedfordVan 0:b9164b348919 239 BLE_GATT_FORMAT_UINT24 = 0x07, /**< Unsigned 24-bit integer. */
MrBedfordVan 0:b9164b348919 240 BLE_GATT_FORMAT_UINT32 = 0x08, /**< Unsigned 32-bit integer. */
MrBedfordVan 0:b9164b348919 241 BLE_GATT_FORMAT_UINT48 = 0x09, /**< Unsigned 48-bit integer. */
MrBedfordVan 0:b9164b348919 242 BLE_GATT_FORMAT_UINT64 = 0x0A, /**< Unsigned 64-bit integer. */
MrBedfordVan 0:b9164b348919 243 BLE_GATT_FORMAT_UINT128 = 0x0B, /**< Unsigned 128-bit integer. */
MrBedfordVan 0:b9164b348919 244 BLE_GATT_FORMAT_SINT8 = 0x0C, /**< Signed 2-bit integer. */
MrBedfordVan 0:b9164b348919 245 BLE_GATT_FORMAT_SINT12 = 0x0D, /**< Signed 12-bit integer. */
MrBedfordVan 0:b9164b348919 246 BLE_GATT_FORMAT_SINT16 = 0x0E, /**< Signed 16-bit integer. */
MrBedfordVan 0:b9164b348919 247 BLE_GATT_FORMAT_SINT24 = 0x0F, /**< Signed 24-bit integer. */
MrBedfordVan 0:b9164b348919 248 BLE_GATT_FORMAT_SINT32 = 0x10, /**< Signed 32-bit integer. */
MrBedfordVan 0:b9164b348919 249 BLE_GATT_FORMAT_SINT48 = 0x11, /**< Signed 48-bit integer. */
MrBedfordVan 0:b9164b348919 250 BLE_GATT_FORMAT_SINT64 = 0x12, /**< Signed 64-bit integer. */
MrBedfordVan 0:b9164b348919 251 BLE_GATT_FORMAT_SINT128 = 0x13, /**< Signed 128-bit integer. */
MrBedfordVan 0:b9164b348919 252 BLE_GATT_FORMAT_FLOAT32 = 0x14, /**< IEEE-754 32-bit floating point. */
MrBedfordVan 0:b9164b348919 253 BLE_GATT_FORMAT_FLOAT64 = 0x15, /**< IEEE-754 64-bit floating point. */
MrBedfordVan 0:b9164b348919 254 BLE_GATT_FORMAT_SFLOAT = 0x16, /**< IEEE-11073 16-bit SFLOAT. */
MrBedfordVan 0:b9164b348919 255 BLE_GATT_FORMAT_FLOAT = 0x17, /**< IEEE-11073 32-bit FLOAT. */
MrBedfordVan 0:b9164b348919 256 BLE_GATT_FORMAT_DUINT16 = 0x18, /**< IEEE-20601 format. */
MrBedfordVan 0:b9164b348919 257 BLE_GATT_FORMAT_UTF8S = 0x19, /**< UTF-8 string. */
MrBedfordVan 0:b9164b348919 258 BLE_GATT_FORMAT_UTF16S = 0x1A, /**< UTF-16 string. */
MrBedfordVan 0:b9164b348919 259 BLE_GATT_FORMAT_STRUCT = 0x1B /**< Opaque Structure. */
MrBedfordVan 0:b9164b348919 260 };
MrBedfordVan 0:b9164b348919 261
MrBedfordVan 0:b9164b348919 262 /**************************************************************************/
MrBedfordVan 0:b9164b348919 263 /*!
MrBedfordVan 0:b9164b348919 264 \brief Standard GATT characteristic properties.
MrBedfordVan 0:b9164b348919 265
MrBedfordVan 0:b9164b348919 266 \note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.1.1
MrBedfordVan 0:b9164b348919 267 and Section 3.3.3.1 for Extended Properties
MrBedfordVan 0:b9164b348919 268 */
MrBedfordVan 0:b9164b348919 269 /**************************************************************************/
MrBedfordVan 0:b9164b348919 270 enum Properties_t {
MrBedfordVan 0:b9164b348919 271 BLE_GATT_CHAR_PROPERTIES_NONE = 0x00,
MrBedfordVan 0:b9164b348919 272 BLE_GATT_CHAR_PROPERTIES_BROADCAST = 0x01, /**< Permits broadcasts of the characteristic value using the Server Characteristic Configuration descriptor. */
MrBedfordVan 0:b9164b348919 273 BLE_GATT_CHAR_PROPERTIES_READ = 0x02, /**< Permits reads of the characteristic value. */
MrBedfordVan 0:b9164b348919 274 BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE = 0x04, /**< Permits writes of the characteristic value without response. */
MrBedfordVan 0:b9164b348919 275 BLE_GATT_CHAR_PROPERTIES_WRITE = 0x08, /**< Permits writes of the characteristic value with response. */
MrBedfordVan 0:b9164b348919 276 BLE_GATT_CHAR_PROPERTIES_NOTIFY = 0x10, /**< Permits notifications of a characteristic value without acknowledgment. */
MrBedfordVan 0:b9164b348919 277 BLE_GATT_CHAR_PROPERTIES_INDICATE = 0x20, /**< Permits indications of a characteristic value with acknowledgment. */
MrBedfordVan 0:b9164b348919 278 BLE_GATT_CHAR_PROPERTIES_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Permits signed writes to the characteristic value. */
MrBedfordVan 0:b9164b348919 279 BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES = 0x80 /**< Additional characteristic properties are defined in the Characteristic Extended Properties descriptor */
MrBedfordVan 0:b9164b348919 280 };
MrBedfordVan 0:b9164b348919 281
MrBedfordVan 0:b9164b348919 282 /**************************************************************************/
MrBedfordVan 0:b9164b348919 283 /*!
MrBedfordVan 0:b9164b348919 284 \brief GATT presentation format wrapper
MrBedfordVan 0:b9164b348919 285
MrBedfordVan 0:b9164b348919 286 \note See Bluetooth Specification 4.0 (Vol. 3), Part G, Section 3.3.3.5
MrBedfordVan 0:b9164b348919 287 \note See https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
MrBedfordVan 0:b9164b348919 288 */
MrBedfordVan 0:b9164b348919 289 /**************************************************************************/
MrBedfordVan 0:b9164b348919 290 struct PresentationFormat_t {
MrBedfordVan 0:b9164b348919 291 uint8_t gatt_format; /**< Format of the value; see @ref ble_gatt_format_t. */
MrBedfordVan 0:b9164b348919 292 int8_t exponent; /**< Exponent for integer data types. Example: if Exponent = -3 and the char value is 3892, the actual value is 3.892 */
MrBedfordVan 0:b9164b348919 293 uint16_t gatt_unit; /**< UUID from Bluetooth Assigned Numbers; see @ref ble_gatt_unit_t. */
MrBedfordVan 0:b9164b348919 294 uint8_t gatt_namespace; /**< Namespace from Bluetooth Assigned Numbers, normally '1'; see @ref BLE_GATT_CPF_NAMESPACES. */
MrBedfordVan 0:b9164b348919 295 uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0'; see @ref BLE_GATT_CPF_NAMESPACES. */
MrBedfordVan 0:b9164b348919 296 };
MrBedfordVan 0:b9164b348919 297
MrBedfordVan 0:b9164b348919 298 /**
MrBedfordVan 0:b9164b348919 299 * @brief Creates a new GattCharacteristic using the specified 16-bit
MrBedfordVan 0:b9164b348919 300 * UUID, value length, and properties.
MrBedfordVan 0:b9164b348919 301 *
MrBedfordVan 0:b9164b348919 302 * @note The UUID value must be unique in the service and is normally >1.
MrBedfordVan 0:b9164b348919 303 *
MrBedfordVan 0:b9164b348919 304 * @param[in] uuid
MrBedfordVan 0:b9164b348919 305 * The UUID to use for this characteristic.
MrBedfordVan 0:b9164b348919 306 * @param[in] valuePtr
MrBedfordVan 0:b9164b348919 307 * The memory holding the initial value. The value is copied
MrBedfordVan 0:b9164b348919 308 * into the stack when the enclosing service is added, and
MrBedfordVan 0:b9164b348919 309 * is thereafter maintained internally by the stack.
MrBedfordVan 0:b9164b348919 310 * @param[in] len
MrBedfordVan 0:b9164b348919 311 * The length in bytes of this characteristic's value.
MrBedfordVan 0:b9164b348919 312 * @param[in] maxLen
MrBedfordVan 0:b9164b348919 313 * The max length in bytes of this characteristic's value.
MrBedfordVan 0:b9164b348919 314 * @param[in] hasVariableLen
MrBedfordVan 0:b9164b348919 315 * Whether the attribute's value length changes over time.
MrBedfordVan 0:b9164b348919 316 * @param[in] props
MrBedfordVan 0:b9164b348919 317 * The 8-bit field containing the characteristic's properties.
MrBedfordVan 0:b9164b348919 318 * @param[in] descriptors
MrBedfordVan 0:b9164b348919 319 * A pointer to an array of descriptors to be included within
MrBedfordVan 0:b9164b348919 320 * this characteristic. The memory for the descriptor array is
MrBedfordVan 0:b9164b348919 321 * owned by the caller, and should remain valid at least until
MrBedfordVan 0:b9164b348919 322 * the enclosing service is added to the GATT table.
MrBedfordVan 0:b9164b348919 323 * @param[in] numDescriptors
MrBedfordVan 0:b9164b348919 324 * The number of descriptors in the previous array.
MrBedfordVan 0:b9164b348919 325 *
MrBedfordVan 0:b9164b348919 326 * @NOTE: If valuePtr == NULL, length == 0, and properties == READ
MrBedfordVan 0:b9164b348919 327 * for the value attribute of a characteristic, then that particular
MrBedfordVan 0:b9164b348919 328 * characteristic may be considered optional and dropped while
MrBedfordVan 0:b9164b348919 329 * instantiating the service with the underlying BLE stack.
MrBedfordVan 0:b9164b348919 330 */
MrBedfordVan 0:b9164b348919 331 GattCharacteristic(const UUID &uuid,
MrBedfordVan 0:b9164b348919 332 uint8_t *valuePtr = NULL,
MrBedfordVan 0:b9164b348919 333 uint16_t len = 0,
MrBedfordVan 0:b9164b348919 334 uint16_t maxLen = 0,
MrBedfordVan 0:b9164b348919 335 uint8_t props = BLE_GATT_CHAR_PROPERTIES_NONE,
MrBedfordVan 0:b9164b348919 336 GattAttribute *descriptors[] = NULL,
MrBedfordVan 0:b9164b348919 337 unsigned numDescriptors = 0,
MrBedfordVan 0:b9164b348919 338 bool hasVariableLen = true) :
MrBedfordVan 0:b9164b348919 339 _valueAttribute(uuid, valuePtr, len, maxLen, hasVariableLen),
MrBedfordVan 0:b9164b348919 340 _properties(props),
MrBedfordVan 0:b9164b348919 341 _requiredSecurity(SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK),
MrBedfordVan 0:b9164b348919 342 _descriptors(descriptors),
MrBedfordVan 0:b9164b348919 343 _descriptorCount(numDescriptors),
MrBedfordVan 0:b9164b348919 344 enabledReadAuthorization(false),
MrBedfordVan 0:b9164b348919 345 enabledWriteAuthorization(false),
MrBedfordVan 0:b9164b348919 346 readAuthorizationCallback(),
MrBedfordVan 0:b9164b348919 347 writeAuthorizationCallback() {
MrBedfordVan 0:b9164b348919 348 /* empty */
MrBedfordVan 0:b9164b348919 349 }
MrBedfordVan 0:b9164b348919 350
MrBedfordVan 0:b9164b348919 351 public:
MrBedfordVan 0:b9164b348919 352 /**
MrBedfordVan 0:b9164b348919 353 * Set up the minimum security (mode and level) requirements for access to the characteristic's value attribute.
MrBedfordVan 0:b9164b348919 354 *
MrBedfordVan 0:b9164b348919 355 * @param securityMode Can be one of encryption or signing, with or without protection for man in the middle attacks (MITM).
MrBedfordVan 0:b9164b348919 356 */
MrBedfordVan 0:b9164b348919 357 void requireSecurity(SecurityManager::SecurityMode_t securityMode) {
MrBedfordVan 0:b9164b348919 358 _requiredSecurity = securityMode;
MrBedfordVan 0:b9164b348919 359 }
MrBedfordVan 0:b9164b348919 360
MrBedfordVan 0:b9164b348919 361 public:
MrBedfordVan 0:b9164b348919 362 /**
MrBedfordVan 0:b9164b348919 363 * Authorization.
MrBedfordVan 0:b9164b348919 364 */
MrBedfordVan 0:b9164b348919 365 void setWriteAuthorizationCallback(void (*callback)(GattWriteAuthCallbackParams *)) {
MrBedfordVan 0:b9164b348919 366 writeAuthorizationCallback.attach(callback);
MrBedfordVan 0:b9164b348919 367 enabledWriteAuthorization = true;
MrBedfordVan 0:b9164b348919 368 }
MrBedfordVan 0:b9164b348919 369 template <typename T>
MrBedfordVan 0:b9164b348919 370 void setWriteAuthorizationCallback(T *object, void (T::*member)(GattWriteAuthCallbackParams *)) {
MrBedfordVan 0:b9164b348919 371 writeAuthorizationCallback.attach(object, member);
MrBedfordVan 0:b9164b348919 372 enabledWriteAuthorization = true;
MrBedfordVan 0:b9164b348919 373 }
MrBedfordVan 0:b9164b348919 374 void setReadAuthorizationCallback(void (*callback)(GattReadAuthCallbackParams *)) {
MrBedfordVan 0:b9164b348919 375 readAuthorizationCallback.attach(callback);
MrBedfordVan 0:b9164b348919 376 enabledReadAuthorization = true;
MrBedfordVan 0:b9164b348919 377 }
MrBedfordVan 0:b9164b348919 378 template <typename T>
MrBedfordVan 0:b9164b348919 379 void setReadAuthorizationCallback(T *object, void (T::*member)(GattReadAuthCallbackParams *)) {
MrBedfordVan 0:b9164b348919 380 readAuthorizationCallback.attach(object, member);
MrBedfordVan 0:b9164b348919 381 enabledReadAuthorization = true;
MrBedfordVan 0:b9164b348919 382 }
MrBedfordVan 0:b9164b348919 383
MrBedfordVan 0:b9164b348919 384 /**
MrBedfordVan 0:b9164b348919 385 * Helper function meant to be called from the guts of the BLE stack to
MrBedfordVan 0:b9164b348919 386 * determine the authorization reply for a write request.
MrBedfordVan 0:b9164b348919 387 * @param params To capture the context of the write-auth request. Also contains an out-parameter for reply.
MrBedfordVan 0:b9164b348919 388 * @return true if the write is authorized to proceed.
MrBedfordVan 0:b9164b348919 389 */
MrBedfordVan 0:b9164b348919 390 GattAuthCallbackReply_t authorizeWrite(GattWriteAuthCallbackParams *params) {
MrBedfordVan 0:b9164b348919 391 if (!isWriteAuthorizationEnabled()) {
MrBedfordVan 0:b9164b348919 392 return AUTH_CALLBACK_REPLY_SUCCESS;
MrBedfordVan 0:b9164b348919 393 }
MrBedfordVan 0:b9164b348919 394
MrBedfordVan 0:b9164b348919 395 params->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS; /* Initialized to no-error by default. */
MrBedfordVan 0:b9164b348919 396 writeAuthorizationCallback.call(params);
MrBedfordVan 0:b9164b348919 397 return params->authorizationReply;
MrBedfordVan 0:b9164b348919 398 }
MrBedfordVan 0:b9164b348919 399
MrBedfordVan 0:b9164b348919 400 /**
MrBedfordVan 0:b9164b348919 401 * Helper function meant to be called from the guts of the BLE stack to
MrBedfordVan 0:b9164b348919 402 * determine the authorization reply for a read request.
MrBedfordVan 0:b9164b348919 403 * @param params To capture the context of the read-auth request.
MrBedfordVan 0:b9164b348919 404 *
MrBedfordVan 0:b9164b348919 405 * @NOTE: To authorize or deny the read the params->authorizationReply field
MrBedfordVan 0:b9164b348919 406 * should be set to true (authorize) or false (deny).
MrBedfordVan 0:b9164b348919 407 *
MrBedfordVan 0:b9164b348919 408 * If the read is approved and params->data is unchanged (NULL),
MrBedfordVan 0:b9164b348919 409 * the current characteristic value will be used.
MrBedfordVan 0:b9164b348919 410 *
MrBedfordVan 0:b9164b348919 411 * If the read is approved, a new value can be provided by setting
MrBedfordVan 0:b9164b348919 412 * the params->data pointer and params->len fields.
MrBedfordVan 0:b9164b348919 413 *
MrBedfordVan 0:b9164b348919 414 * @return true if the read is authorized to proceed.
MrBedfordVan 0:b9164b348919 415 */
MrBedfordVan 0:b9164b348919 416 GattAuthCallbackReply_t authorizeRead(GattReadAuthCallbackParams *params) {
MrBedfordVan 0:b9164b348919 417 if (!isReadAuthorizationEnabled()) {
MrBedfordVan 0:b9164b348919 418 return AUTH_CALLBACK_REPLY_SUCCESS;
MrBedfordVan 0:b9164b348919 419 }
MrBedfordVan 0:b9164b348919 420
MrBedfordVan 0:b9164b348919 421 params->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS; /* Initialized to no-error by default. */
MrBedfordVan 0:b9164b348919 422 readAuthorizationCallback.call(params);
MrBedfordVan 0:b9164b348919 423 return params->authorizationReply;
MrBedfordVan 0:b9164b348919 424 }
MrBedfordVan 0:b9164b348919 425
MrBedfordVan 0:b9164b348919 426 /* accessors */
MrBedfordVan 0:b9164b348919 427 public:
MrBedfordVan 0:b9164b348919 428 GattAttribute& getValueAttribute() {return _valueAttribute; }
MrBedfordVan 0:b9164b348919 429 const GattAttribute& getValueAttribute() const {return _valueAttribute; }
MrBedfordVan 0:b9164b348919 430 GattAttribute::Handle_t getValueHandle(void) const {return getValueAttribute().getHandle();}
MrBedfordVan 0:b9164b348919 431 uint8_t getProperties(void) const {return _properties; }
MrBedfordVan 0:b9164b348919 432 SecurityManager::SecurityMode_t getRequiredSecurity() const {return _requiredSecurity; }
MrBedfordVan 0:b9164b348919 433 uint8_t getDescriptorCount(void) const {return _descriptorCount; }
MrBedfordVan 0:b9164b348919 434 bool isReadAuthorizationEnabled() const {return enabledReadAuthorization; }
MrBedfordVan 0:b9164b348919 435 bool isWriteAuthorizationEnabled() const {return enabledWriteAuthorization; }
MrBedfordVan 0:b9164b348919 436
MrBedfordVan 0:b9164b348919 437 GattAttribute *getDescriptor(uint8_t index) {
MrBedfordVan 0:b9164b348919 438 if (index >= _descriptorCount) {
MrBedfordVan 0:b9164b348919 439 return NULL;
MrBedfordVan 0:b9164b348919 440 }
MrBedfordVan 0:b9164b348919 441
MrBedfordVan 0:b9164b348919 442 return _descriptors[index];
MrBedfordVan 0:b9164b348919 443 }
MrBedfordVan 0:b9164b348919 444
MrBedfordVan 0:b9164b348919 445 private:
MrBedfordVan 0:b9164b348919 446 GattAttribute _valueAttribute;
MrBedfordVan 0:b9164b348919 447 uint8_t _properties;
MrBedfordVan 0:b9164b348919 448 SecurityManager::SecurityMode_t _requiredSecurity;
MrBedfordVan 0:b9164b348919 449 GattAttribute **_descriptors;
MrBedfordVan 0:b9164b348919 450 uint8_t _descriptorCount;
MrBedfordVan 0:b9164b348919 451
MrBedfordVan 0:b9164b348919 452 bool enabledReadAuthorization;
MrBedfordVan 0:b9164b348919 453 bool enabledWriteAuthorization;
MrBedfordVan 0:b9164b348919 454 FunctionPointerWithContext<GattReadAuthCallbackParams *> readAuthorizationCallback;
MrBedfordVan 0:b9164b348919 455 FunctionPointerWithContext<GattWriteAuthCallbackParams *> writeAuthorizationCallback;
MrBedfordVan 0:b9164b348919 456
MrBedfordVan 0:b9164b348919 457 private:
MrBedfordVan 0:b9164b348919 458 /* Disallow copy and assignment. */
MrBedfordVan 0:b9164b348919 459 GattCharacteristic(const GattCharacteristic &);
MrBedfordVan 0:b9164b348919 460 GattCharacteristic& operator=(const GattCharacteristic &);
MrBedfordVan 0:b9164b348919 461 };
MrBedfordVan 0:b9164b348919 462
MrBedfordVan 0:b9164b348919 463 template <typename T>
MrBedfordVan 0:b9164b348919 464 class ReadOnlyGattCharacteristic : public GattCharacteristic {
MrBedfordVan 0:b9164b348919 465 public:
MrBedfordVan 0:b9164b348919 466 ReadOnlyGattCharacteristic<T>(const UUID &uuid,
MrBedfordVan 0:b9164b348919 467 T *valuePtr,
MrBedfordVan 0:b9164b348919 468 uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
MrBedfordVan 0:b9164b348919 469 GattAttribute *descriptors[] = NULL,
MrBedfordVan 0:b9164b348919 470 unsigned numDescriptors = 0) :
MrBedfordVan 0:b9164b348919 471 GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
MrBedfordVan 0:b9164b348919 472 BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties, descriptors, numDescriptors, false) {
MrBedfordVan 0:b9164b348919 473 /* empty */
MrBedfordVan 0:b9164b348919 474 }
MrBedfordVan 0:b9164b348919 475 };
MrBedfordVan 0:b9164b348919 476
MrBedfordVan 0:b9164b348919 477 template <typename T>
MrBedfordVan 0:b9164b348919 478 class WriteOnlyGattCharacteristic : public GattCharacteristic {
MrBedfordVan 0:b9164b348919 479 public:
MrBedfordVan 0:b9164b348919 480 WriteOnlyGattCharacteristic<T>(const UUID &uuid,
MrBedfordVan 0:b9164b348919 481 T *valuePtr,
MrBedfordVan 0:b9164b348919 482 uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
MrBedfordVan 0:b9164b348919 483 GattAttribute *descriptors[] = NULL,
MrBedfordVan 0:b9164b348919 484 unsigned numDescriptors = 0) :
MrBedfordVan 0:b9164b348919 485 GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
MrBedfordVan 0:b9164b348919 486 BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
MrBedfordVan 0:b9164b348919 487 /* empty */
MrBedfordVan 0:b9164b348919 488 }
MrBedfordVan 0:b9164b348919 489 };
MrBedfordVan 0:b9164b348919 490
MrBedfordVan 0:b9164b348919 491 template <typename T>
MrBedfordVan 0:b9164b348919 492 class ReadWriteGattCharacteristic : public GattCharacteristic {
MrBedfordVan 0:b9164b348919 493 public:
MrBedfordVan 0:b9164b348919 494 ReadWriteGattCharacteristic<T>(const UUID &uuid,
MrBedfordVan 0:b9164b348919 495 T *valuePtr,
MrBedfordVan 0:b9164b348919 496 uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
MrBedfordVan 0:b9164b348919 497 GattAttribute *descriptors[] = NULL,
MrBedfordVan 0:b9164b348919 498 unsigned numDescriptors = 0) :
MrBedfordVan 0:b9164b348919 499 GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
MrBedfordVan 0:b9164b348919 500 BLE_GATT_CHAR_PROPERTIES_READ | BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
MrBedfordVan 0:b9164b348919 501 /* empty */
MrBedfordVan 0:b9164b348919 502 }
MrBedfordVan 0:b9164b348919 503 };
MrBedfordVan 0:b9164b348919 504
MrBedfordVan 0:b9164b348919 505 template <typename T, unsigned NUM_ELEMENTS>
MrBedfordVan 0:b9164b348919 506 class WriteOnlyArrayGattCharacteristic : public GattCharacteristic {
MrBedfordVan 0:b9164b348919 507 public:
MrBedfordVan 0:b9164b348919 508 WriteOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid,
MrBedfordVan 0:b9164b348919 509 T valuePtr[NUM_ELEMENTS],
MrBedfordVan 0:b9164b348919 510 uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
MrBedfordVan 0:b9164b348919 511 GattAttribute *descriptors[] = NULL,
MrBedfordVan 0:b9164b348919 512 unsigned numDescriptors = 0) :
MrBedfordVan 0:b9164b348919 513 GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
MrBedfordVan 0:b9164b348919 514 BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
MrBedfordVan 0:b9164b348919 515 /* empty */
MrBedfordVan 0:b9164b348919 516 }
MrBedfordVan 0:b9164b348919 517 };
MrBedfordVan 0:b9164b348919 518
MrBedfordVan 0:b9164b348919 519 template <typename T, unsigned NUM_ELEMENTS>
MrBedfordVan 0:b9164b348919 520 class ReadOnlyArrayGattCharacteristic : public GattCharacteristic {
MrBedfordVan 0:b9164b348919 521 public:
MrBedfordVan 0:b9164b348919 522 ReadOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid,
MrBedfordVan 0:b9164b348919 523 T valuePtr[NUM_ELEMENTS],
MrBedfordVan 0:b9164b348919 524 uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
MrBedfordVan 0:b9164b348919 525 GattAttribute *descriptors[] = NULL,
MrBedfordVan 0:b9164b348919 526 unsigned numDescriptors = 0) :
MrBedfordVan 0:b9164b348919 527 GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
MrBedfordVan 0:b9164b348919 528 BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties, descriptors, numDescriptors, false) {
MrBedfordVan 0:b9164b348919 529 /* empty */
MrBedfordVan 0:b9164b348919 530 }
MrBedfordVan 0:b9164b348919 531 };
MrBedfordVan 0:b9164b348919 532
MrBedfordVan 0:b9164b348919 533 template <typename T, unsigned NUM_ELEMENTS>
MrBedfordVan 0:b9164b348919 534 class ReadWriteArrayGattCharacteristic : public GattCharacteristic {
MrBedfordVan 0:b9164b348919 535 public:
MrBedfordVan 0:b9164b348919 536 ReadWriteArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid,
MrBedfordVan 0:b9164b348919 537 T valuePtr[NUM_ELEMENTS],
MrBedfordVan 0:b9164b348919 538 uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE,
MrBedfordVan 0:b9164b348919 539 GattAttribute *descriptors[] = NULL,
MrBedfordVan 0:b9164b348919 540 unsigned numDescriptors = 0) :
MrBedfordVan 0:b9164b348919 541 GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
MrBedfordVan 0:b9164b348919 542 BLE_GATT_CHAR_PROPERTIES_READ | BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties, descriptors, numDescriptors) {
MrBedfordVan 0:b9164b348919 543 /* empty */
MrBedfordVan 0:b9164b348919 544 }
MrBedfordVan 0:b9164b348919 545 };
MrBedfordVan 0:b9164b348919 546
MrBedfordVan 0:b9164b348919 547 #endif // ifndef __GATT_CHARACTERISTIC_H__