From bf104d42cb26e34b03e3b9c8dbfa9dc6f4eecc85 Mon Sep 17 00:00:00 2001 From: Sayooj K Karun Date: Tue, 22 Apr 2025 14:57:48 +0530 Subject: [PATCH] bluetooth: mtu_update: peripheral: Add NULL check Add NULL check for connection context, and only send the notification if connection is established. Signed-off-by: Sayooj K Karun --- .../mtu_update/peripheral/src/peripheral_mtu_update.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c b/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c index a5bbef6f5ee..44ac61ac33e 100644 --- a/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c +++ b/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c @@ -97,8 +97,10 @@ void run_peripheral_sample(uint8_t *notify_data, size_t notify_data_size, uint16 for (int i = 0; (i < seconds) || infinite; i++) { k_sleep(K_SECONDS(1)); + if (default_conn == NULL) { + printk("Skipping notification since connection is not yet established\n"); /* Only send the notification if the UATT MTU supports the required length */ - if (bt_gatt_get_uatt_mtu(default_conn) >= ATT_NTF_SIZE(notify_data_size)) { + } else if (bt_gatt_get_uatt_mtu(default_conn) >= ATT_NTF_SIZE(notify_data_size)) { bt_gatt_notify(default_conn, notify_crch, notify_data, notify_data_size); } else { printk("Skipping notification since UATT MTU is not sufficient."