@@ -1429,6 +1429,12 @@ class GattCharacteristic {
14291429 GattCharacteristic (const GattCharacteristic &) = delete;
14301430 GattCharacteristic& operator =(const GattCharacteristic &) = delete ;
14311431
1432+ ~GattCharacteristic () {
1433+ if (_implicit_cccd != nullptr ) {
1434+ delete _implicit_cccd;
1435+ }
1436+ }
1437+
14321438public:
14331439
14341440 /* *
@@ -1714,7 +1720,7 @@ class GattCharacteristic {
17141720 */
17151721 uint8_t getDescriptorCount () const
17161722 {
1717- return _descriptorCount;
1723+ return (_implicit_cccd == nullptr ? _descriptorCount : _descriptorCount+ 1 ) ;
17181724 }
17191725
17201726 /* *
@@ -1750,16 +1756,40 @@ class GattCharacteristic {
17501756 *
17511757 * @return A pointer the requested descriptor if @p index is within the
17521758 * range of the descriptor array or nullptr otherwise.
1759+ *
1760+ * @note if this characteristic has an implicitly-created CCCD this
1761+ * descriptor will be available at the highest index
1762+ * (ie: return of getDescriptorCount() - 1)
17531763 */
17541764 GattAttribute *getDescriptor (uint8_t index)
17551765 {
1756- if (index >= _descriptorCount) {
1766+
1767+ if (index == _descriptorCount) {
1768+ // If _implicit_cccd is nullptr, we want to return that anyway
1769+ return _implicit_cccd;
1770+ }
1771+ else if (index > _descriptorCount) {
17571772 return nullptr ;
17581773 }
17591774
17601775 return _descriptors[index];
17611776 }
17621777
1778+ /* *
1779+ * Sets this GattCharacteristic's implicitly-created CCCD, if
1780+ * applicable.
1781+ *
1782+ * @note once this is called, the pointed-to GattAttribute
1783+ * is owned by this GattCharacteristic and will be deleted
1784+ * during this object's destructor
1785+ *
1786+ * @note this is an internal function and should not be called
1787+ * by the application
1788+ */
1789+ void _setImplicitCCCD (GattAttribute *implicit_cccd) {
1790+ _implicit_cccd = implicit_cccd;
1791+ }
1792+
17631793private:
17641794
17651795 /* *
@@ -1783,6 +1813,16 @@ class GattCharacteristic {
17831813 */
17841814 uint8_t _descriptorCount;
17851815
1816+ /* *
1817+ * Pointer to characteristic's implicit CCCD, if applicable
1818+ *
1819+ * @note this is only populated if the stack creates an implicit CCCD
1820+ * for this GattCharacteristic. If the descriptors array passed into
1821+ * the constructor includes a CCCD this field is left as nullptr to
1822+ * indicate the CCCD was explicitly created.
1823+ */
1824+ GattAttribute* _implicit_cccd;
1825+
17861826 /* *
17871827 * The registered callback handler for read authorization reply.
17881828 */
0 commit comments