Skip to content

Commit bf104d4

Browse files
sayooj-atmosickartben
authored andcommitted
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 <[email protected]>
1 parent 9aba132 commit bf104d4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ void run_peripheral_sample(uint8_t *notify_data, size_t notify_data_size, uint16
9797

9898
for (int i = 0; (i < seconds) || infinite; i++) {
9999
k_sleep(K_SECONDS(1));
100+
if (default_conn == NULL) {
101+
printk("Skipping notification since connection is not yet established\n");
100102
/* Only send the notification if the UATT MTU supports the required length */
101-
if (bt_gatt_get_uatt_mtu(default_conn) >= ATT_NTF_SIZE(notify_data_size)) {
103+
} else if (bt_gatt_get_uatt_mtu(default_conn) >= ATT_NTF_SIZE(notify_data_size)) {
102104
bt_gatt_notify(default_conn, notify_crch, notify_data, notify_data_size);
103105
} else {
104106
printk("Skipping notification since UATT MTU is not sufficient."

0 commit comments

Comments
 (0)