From 1ae0eb5ce8adafcec993e6fb8f4eeb6f818a7772 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 29 Nov 2023 12:01:14 -0800 Subject: [PATCH] bluetooth: Add CPF attribute to BAS battery level. BAS v1.1, section 3.1.2.1 notes that a CPF should be added if the device has more that one instance of the Battery Service, so add one with the `main` description so that apps can add additional Battery Level services with other descriptions, e.g. `auxiliary`. Signed-off-by: Peter Johanson --- subsys/bluetooth/services/bas.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/subsys/bluetooth/services/bas.c b/subsys/bluetooth/services/bas.c index e6af782f877c00..cf6482d539770c 100644 --- a/subsys/bluetooth/services/bas.c +++ b/subsys/bluetooth/services/bas.c @@ -47,6 +47,17 @@ static ssize_t read_blvl(struct bt_conn *conn, sizeof(lvl8)); } +/* Constant values from the Assigned Numbers specification: + * https://www.bluetooth.com/wp-content/uploads/Files/Specification/Assigned_Numbers.pdf?id=89 + */ +static const struct bt_gatt_cpf level_cpf = { + .format = 0x04, /* uint8 */ + .exponent = 0x0, + .unit = 0x27AD, /* Percentage */ + .name_space = 0x01, /* Bluetooth SIG */ + .description = 0x0106, /* "main" */ +}; + BT_GATT_SERVICE_DEFINE(bas, BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS), BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL, @@ -55,6 +66,7 @@ BT_GATT_SERVICE_DEFINE(bas, &battery_level), BT_GATT_CCC(blvl_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), + BT_GATT_CPF(&level_cpf), ); static int bas_init(const struct device *dev)