• Jimmy Durand Wesolowski's avatar
    Fixing BLE GATT Characteristic notification and Characteristic Descriptor read (#4464) · 360e04fa
    Jimmy Durand Wesolowski authored
    * BLERemoteChar: fix descriptor 2902 write for characteristic notifications
    
    When registering a notification on a characteristic, the 2902 descriptor
    (CCCD) value is set to 1 (or 2 for indication).
    According to the BLUETOOTH CORE SPECIFICATION Version 5.2, Revision Date
    2019-12-31, section 4.12.3 "Write Characteristic Descriptors" (page 1588),
    the characteristic descriptor write must expect a response.
    Currently, the descriptor write is performed without expecting a reponse,
    which prevents the notification to be functional with some BLE stacks.
    This commit modify the write to expect the response.
    Signed-off-by: default avatarJimmy Durand Wesolowski <jimmy.durand.wesolowski@commsolid.com>
    
    * BLERemoteChar: forward GATT client event to characteristic descriptors
    
    This commits prevents a permanent wait when calling BLERemoteDescriptor
    readValue function, on the m_semaphoreReadDescrEvt semaphore.
    
    ESP32 BLE stack calls to remote characteristic
    - notification,
    - value read
    - value write
    and remote characteristic descriptor
    - value read
    are asynchronous.
    
    When such a call is performed by this library, a semaphore is taken prior
    to the BLE stack read or write operation, and waited on after it.
    
    Releasing the semaphore is done by the characteristic event handling
    function (gattClientEventHandler), when the appropriate event is received.
    
    However, the characteristic descriptor events are discarded, and the
    value read semaphore is never released.
    
    This commits forwards the GATT client events from the remote
    characteristic down to their remote characteristic descriptor, and
    implements their event handling.
    
    Adding a semaphore for the remote characteristic descriptor value write
    will be done in a separate commit.
    Signed-off-by: default avatarJimmy Durand Wesolowski <jimmy.durand.wesolowski@commsolid.com>
    
    * BLERemoteDescriptor: add semaphore to characteristic descriptor write
    
    This adds a semaphore to characteristic descriptor value write, to mimic
    the value read function, and to ensure completion of the operation before
    we carry on.
    Signed-off-by: default avatarJimmy Durand Wesolowski <jimmy.durand.wesolowski@commsolid.com>
    Co-authored-by: default avatarJimmy Durand Wesolowski <jimmy.durand.wesolowski@commsolid.com>
    360e04fa
BLERemoteDescriptor.cpp 5.66 KB