summaryrefslogtreecommitdiff
path: root/src/components/ble
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-04-04 15:19:37 +0200
committerJean-François Milants <jf@codingfield.com>2021-04-04 15:19:37 +0200
commit3934e9bef20c5c2ad393e20cfff3a5a1b0d24569 (patch)
tree5c8042f34d7e2bbb2f5ee6a0fbab2843d0897115 /src/components/ble
parent1b71a10bebb63a1b93583d20d657d7accb6b3ddf (diff)
Ignore notification with empty message.
Diffstat (limited to 'src/components/ble')
-rw-r--r--src/components/ble/AlertNotificationClient.cpp7
-rw-r--r--src/components/ble/AlertNotificationService.cpp7
2 files changed, 10 insertions, 4 deletions
diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp
index cfb3272d..9efede39 100644
--- a/src/components/ble/AlertNotificationClient.cpp
+++ b/src/components/ble/AlertNotificationClient.cpp
@@ -158,8 +158,11 @@ void AlertNotificationClient::OnNotification(ble_gap_event *event) {
const auto maxMessageSize{NotificationManager::MaximumMessageSize()};
const auto maxBufferSize{maxMessageSize + headerSize};
- const auto dbgPacketLen = OS_MBUF_PKTLEN(event->notify_rx.om);
- size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
+ // Ignore notifications with empty message
+ const auto packetLen = OS_MBUF_PKTLEN(event->notify_rx.om);
+ if(packetLen <= headerSize) return;
+
+ size_t bufferSize = std::min(packetLen + stringTerminatorSize, maxBufferSize);
auto messageSize = std::min(maxMessageSize, (bufferSize - headerSize));
NotificationManager::Notification notif;
diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp
index c3187c1d..d91e2090 100644
--- a/src/components/ble/AlertNotificationService.cpp
+++ b/src/components/ble/AlertNotificationService.cpp
@@ -66,8 +66,11 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
const auto maxMessageSize {NotificationManager::MaximumMessageSize()};
const auto maxBufferSize{maxMessageSize + headerSize};
- const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om);
- size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
+ // Ignore notifications with empty message
+ const auto packetLen = OS_MBUF_PKTLEN(ctxt->om);
+ if(packetLen <= headerSize) return 0;
+
+ size_t bufferSize = std::min(packetLen + stringTerminatorSize, maxBufferSize);
auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize));
Categories category;