Lightly modified version of the BLE stack, that doesn't bring up a DFUService by default... as we have our own.
Fork of BLE_API by
Diff: public/GattCharacteristic.h
- Revision:
- 350:64b656246a72
- Parent:
- 345:b977276fb4d3
- Child:
- 354:cfe0a8bafaaa
--- a/public/GattCharacteristic.h Fri May 08 15:35:46 2015 +0100 +++ b/public/GattCharacteristic.h Fri May 08 15:35:46 2015 +0100 @@ -290,6 +290,14 @@ uint16_t gatt_nsdesc; /**< Namespace description from Bluetooth Assigned Numbers, normally '0', see @ref BLE_GATT_CPF_NAMESPACES. */ } presentation_format_t; + enum ble_gatt_char_required_security_t { + SECURITY_MODE_ENCRYPTION_OPEN_LINK = 0x00, /**< Set security mode to require no protection, open link. */ + SECURITY_MODE_ENCRYPTION_NO_MITM = 0x01, /**< Set security mode to require encryption, but no MITM protection. */ + SECURITY_MODE_ENCRYPTION_WITH_MITM = 0x02, /**< Set security mode to require encryption and MITM protection. */ + SECURITY_MODE_SIGNED_NO_MITM = 0x04, /**< Set security mode to require signing or encryption, but no MITM protection. */ + SECURITY_MODE_SIGNED_WITH_MITM = 0x08, /**< Set security mode to require signing or encryption, and MITM protection. */ + }; + /** * @brief Creates a new GattCharacteristic using the specified 16-bit * UUID, value length, and properties @@ -330,6 +338,7 @@ unsigned numDescriptors = 0) : _valueAttribute(uuid, valuePtr, initialLen, maxLen), _properties(props), + _requiredSecurity(), _descriptors(descriptors), _descriptorCount(numDescriptors), enabledReadAuthorization(false), @@ -339,10 +348,15 @@ /* empty */ } +public: + void requireSecurity(ble_gatt_char_required_security_t securityMode) { + _requiredSecurity = securityMode; + } + +public: /** * Authorization. */ -public: void setWriteAuthorizationCallback(void (*callback)(GattCharacteristicWriteAuthCBParams *)) { writeAuthorizationCallback.attach(callback); enabledWriteAuthorization = true; @@ -406,13 +420,14 @@ /* accessors */ public: - GattAttribute& getValueAttribute() {return _valueAttribute; } - const GattAttribute& getValueAttribute() const {return _valueAttribute; } - GattAttribute::Handle_t getValueHandle(void) const {return getValueAttribute().getHandle();} - uint8_t getProperties(void) const {return _properties; } - uint8_t getDescriptorCount(void) const {return _descriptorCount; } - bool isReadAuthorizationEnabled() const {return enabledReadAuthorization; } - bool isWriteAuthorizationEnabled() const {return enabledWriteAuthorization; } + GattAttribute& getValueAttribute() {return _valueAttribute; } + const GattAttribute& getValueAttribute() const {return _valueAttribute; } + GattAttribute::Handle_t getValueHandle(void) const {return getValueAttribute().getHandle();} + uint8_t getProperties(void) const {return _properties; } + ble_gatt_char_required_security_t getRequiredSecurity() const {return _requiredSecurity; } + uint8_t getDescriptorCount(void) const {return _descriptorCount; } + bool isReadAuthorizationEnabled() const {return enabledReadAuthorization; } + bool isWriteAuthorizationEnabled() const {return enabledWriteAuthorization; } GattAttribute *getDescriptor(uint8_t index) { if (index >= _descriptorCount) { @@ -423,13 +438,14 @@ } private: - GattAttribute _valueAttribute; - uint8_t _properties; - GattAttribute **_descriptors; - uint8_t _descriptorCount; + GattAttribute _valueAttribute; + uint8_t _properties; + ble_gatt_char_required_security_t _requiredSecurity; + GattAttribute **_descriptors; + uint8_t _descriptorCount; - bool enabledReadAuthorization; - bool enabledWriteAuthorization; + bool enabledReadAuthorization; + bool enabledWriteAuthorization; FunctionPointerWithContext<GattCharacteristicReadAuthCBParams *> readAuthorizationCallback; FunctionPointerWithContext<GattCharacteristicWriteAuthCBParams *> writeAuthorizationCallback;