diff --git a/drivers/nble/gatt.c b/drivers/nble/gatt.c index afc4b20bad4..858bdaa4fda 100644 --- a/drivers/nble/gatt.c +++ b/drivers/nble/gatt.c @@ -96,8 +96,8 @@ int bt_gatt_attr_read_cpf(struct bt_conn *conn, return -ENOSYS; } -int bt_gatt_notify(struct bt_conn *conn, uint16_t handle, const void *data, - uint16_t len) +int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr, + const void *data, uint16_t len) { return -ENOSYS; } diff --git a/include/bluetooth/gatt.h b/include/bluetooth/gatt.h index f0e4c81f36b..5aa487567f1 100644 --- a/include/bluetooth/gatt.h +++ b/include/bluetooth/gatt.h @@ -670,12 +670,12 @@ int bt_gatt_attr_read_cpf(struct bt_conn *conn, * notification only the given connection. * * @param conn Connection object. - * @param handle Attribute handle. + * @param attr Attribute object. * @param value Attribute value. * @param len Attribute value length. */ -int bt_gatt_notify(struct bt_conn *conn, uint16_t handle, const void *data, - uint16_t len); +int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr, + const void *data, uint16_t len); #if defined(CONFIG_BLUETOOTH_GATT_CLIENT) /* Client API */ diff --git a/net/bluetooth/gatt.c b/net/bluetooth/gatt.c index 0ddb1d8a0f6..8b82fcee65d 100644 --- a/net/bluetooth/gatt.c +++ b/net/bluetooth/gatt.c @@ -471,20 +471,24 @@ static uint8_t notify_cb(const struct bt_gatt_attr *attr, void *user_data) return BT_GATT_ITER_CONTINUE; } -int bt_gatt_notify(struct bt_conn *conn, uint16_t handle, const void *data, - uint16_t len) +int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr, + const void *data, uint16_t len) { struct notify_data nfy; - if (conn) { - return att_notify(conn, handle, data, len); + if (!attr || !attr->handle) { + return -EINVAL; } - nfy.handle = handle; + if (conn) { + return att_notify(conn, attr->handle, data, len); + } + + nfy.handle = attr->handle; nfy.data = data; nfy.len = len; - bt_gatt_foreach_attr(handle, 0xffff, notify_cb, &nfy); + bt_gatt_foreach_attr(attr->handle, 0xffff, notify_cb, &nfy); return 0; } diff --git a/samples/bluetooth/nble/src/main.c b/samples/bluetooth/nble/src/main.c index 99878fbaca9..f420a204cb8 100644 --- a/samples/bluetooth/nble/src/main.c +++ b/samples/bluetooth/nble/src/main.c @@ -495,7 +495,7 @@ void main(void) /* Current Time Service updates only when time is changed */ if (ct_update) { ct_update = 0; - bt_gatt_notify(NULL, 0x0014, &ct, sizeof(ct)); + bt_gatt_notify(NULL, &attrs[20], &ct, sizeof(ct)); } /* Heartrate measurements simulation */ @@ -505,7 +505,7 @@ void main(void) hrm[1] = 90; } - bt_gatt_notify(NULL, 0x0008, &hrm, sizeof(hrm)); + bt_gatt_notify(NULL, &attrs[8], &hrm, sizeof(hrm)); } /* Battery level simulation */ @@ -517,7 +517,8 @@ void main(void) battery = 100; } - bt_gatt_notify(NULL, 0x0010, &battery, sizeof(battery)); + bt_gatt_notify(NULL, &attrs[16], &battery, + sizeof(battery)); } } } diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c index 53ca71ab454..cb482a70130 100644 --- a/samples/bluetooth/peripheral/src/main.c +++ b/samples/bluetooth/peripheral/src/main.c @@ -510,7 +510,7 @@ void main(void) /* Current Time Service updates only when time is changed */ if (ct_update) { ct_update = 0; - bt_gatt_notify(NULL, 0x0014, &ct, sizeof(ct)); + bt_gatt_notify(NULL, &cts_attrs[3], &ct, sizeof(ct)); } /* Heartrate measurements simulation */ @@ -518,7 +518,7 @@ void main(void) hrm[0] = 0x06; /* uint8, sensor contact */ hrm[1] = 90 + (sys_rand32_get() % 20); - bt_gatt_notify(NULL, 0x0008, &hrm, sizeof(hrm)); + bt_gatt_notify(NULL, &hrs_attrs[3], &hrm, sizeof(hrm)); } /* Battery level simulation */ @@ -530,7 +530,8 @@ void main(void) battery = 100; } - bt_gatt_notify(NULL, 0x0010, &battery, sizeof(battery)); + bt_gatt_notify(NULL, &bas_attrs[3], &battery, + sizeof(battery)); } } } diff --git a/samples/bluetooth/tester/src/gatt.c b/samples/bluetooth/tester/src/gatt.c index b99ee15bdbf..a23c7f9d6da 100644 --- a/samples/bluetooth/tester/src/gatt.c +++ b/samples/bluetooth/tester/src/gatt.c @@ -653,8 +653,8 @@ static uint8_t set_value_cb(struct bt_gatt_attr *attr, void *user_data) memcpy(gatt_value->data, cmd->value, gatt_value->len); if (gatt_value->has_ccc) { - bt_gatt_notify(NULL, attr->handle, - gatt_value->data, gatt_value->len); + bt_gatt_notify(NULL, attr, gatt_value->data, + gatt_value->len); } status = BTP_STATUS_SUCCESS;