Skip to content

Commit

Permalink
softdevice: don't send a notify/indicate without a CCCD
Browse files Browse the repository at this point in the history
sd_ble_gatts_hvx_noescape can only be called when the notify/indicate
permission is set (and therefore a CCCD has been added). Without it, it
will just return an error.

This fixes a problem I found on the PineTime, while implementing the
battery service.
  • Loading branch information
aykevl authored and deadprogram committed Dec 25, 2023
1 parent b5d4e3f commit ec80e01
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gatts_sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *Characteristic) Write(p []byte) (n int, err error) {
}

connHandle := currentConnection.Get()
if connHandle != C.BLE_CONN_HANDLE_INVALID {
if connHandle != C.BLE_CONN_HANDLE_INVALID && c.permissions&(CharacteristicNotifyPermission|CharacteristicIndicatePermission) != 0 {
// There is a connected central.
p_len := uint16(len(p))
errCode := C.sd_ble_gatts_hvx_noescape(connHandle,
Expand Down

0 comments on commit ec80e01

Please sign in to comment.