Skip to content

Commit dd5a0d1

Browse files
kapi-nojhedberg
authored andcommitted
bluetooth: services: hrs: add characteristic permission config
Added a configuration of characteristic access permissions for Bluetooth Heart Rate service. Signed-off-by: Kamil Piszczek <[email protected]>
1 parent 52837aa commit dd5a0d1

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

subsys/bluetooth/services/Kconfig.hrs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66
menuconfig BT_HRS
77
bool "Enable GATT Heart Rate service"
88

9+
if BT_HRS
10+
11+
choice
12+
prompt "Default permissions used for HRS characteristics"
13+
default BT_HRS_DEFAULT_PERM_RW
14+
help
15+
Default permissions for HRS characteristic attributes
16+
used when no permission is set for the report.
17+
Used also for boot reports.
18+
19+
config BT_HRS_DEFAULT_PERM_RW
20+
bool "Read and write allowed"
21+
22+
config BT_HRS_DEFAULT_PERM_RW_ENCRYPT
23+
bool "Require encryption for access"
24+
25+
config BT_HRS_DEFAULT_PERM_RW_AUTHEN
26+
bool "Require encryption and authentication for access"
27+
28+
endchoice
29+
930
config BT_HRS_LOG_LEVEL
1031
int "Heart Rate service log level"
1132
depends on LOG
@@ -20,3 +41,5 @@ config BT_HRS_LOG_LEVEL
2041
2 WARNING, write LOG_WRN in addition to previous level
2142
3 INFO, write LOG_INF in addition to previous levels
2243
4 DEBUG, write LOG_DBG in addition to previous levels
44+
45+
endif # BT_HRS

subsys/bluetooth/services/hrs.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@
2525
#include <logging/log.h>
2626
LOG_MODULE_REGISTER(hrs);
2727

28+
29+
#define GATT_PERM_READ_MASK (BT_GATT_PERM_READ | \
30+
BT_GATT_PERM_READ_ENCRYPT | \
31+
BT_GATT_PERM_READ_AUTHEN)
32+
#define GATT_PERM_WRITE_MASK (BT_GATT_PERM_WRITE | \
33+
BT_GATT_PERM_WRITE_ENCRYPT | \
34+
BT_GATT_PERM_WRITE_AUTHEN)
35+
36+
#ifndef CONFIG_BT_HRS_DEFAULT_PERM_RW_AUTHEN
37+
#define CONFIG_BT_HRS_DEFAULT_PERM_RW_AUTHEN 0
38+
#endif
39+
#ifndef CONFIG_BT_HRS_DEFAULT_PERM_RW_ENCRYPT
40+
#define CONFIG_BT_HRS_DEFAULT_PERM_RW_ENCRYPT 0
41+
#endif
42+
#ifndef CONFIG_BT_HRS_DEFAULT_PERM_RW
43+
#define CONFIG_BT_HRS_DEFAULT_PERM_RW 0
44+
#endif
45+
46+
#define HRS_GATT_PERM_DEFAULT ( \
47+
CONFIG_BT_HRS_DEFAULT_PERM_RW_AUTHEN ? \
48+
(BT_GATT_PERM_READ_AUTHEN | BT_GATT_PERM_WRITE_AUTHEN) : \
49+
CONFIG_BT_HRS_DEFAULT_PERM_RW_ENCRYPT ? \
50+
(BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT) : \
51+
(BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)) \
52+
2853
static uint8_t hrs_blsc;
2954

3055
static void hrmc_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
@@ -49,11 +74,13 @@ BT_GATT_SERVICE_DEFINE(hrs_svc,
4974
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_MEASUREMENT, BT_GATT_CHRC_NOTIFY,
5075
BT_GATT_PERM_NONE, NULL, NULL, NULL),
5176
BT_GATT_CCC(hrmc_ccc_cfg_changed,
52-
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
77+
HRS_GATT_PERM_DEFAULT),
5378
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_BODY_SENSOR, BT_GATT_CHRC_READ,
54-
BT_GATT_PERM_READ, read_blsc, NULL, NULL),
79+
HRS_GATT_PERM_DEFAULT & GATT_PERM_READ_MASK,
80+
read_blsc, NULL, NULL),
5581
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_CONTROL_POINT, BT_GATT_CHRC_WRITE,
56-
BT_GATT_PERM_NONE, NULL, NULL, NULL),
82+
HRS_GATT_PERM_DEFAULT & GATT_PERM_WRITE_MASK,
83+
NULL, NULL, NULL),
5784
);
5885

5986
static int hrs_init(const struct device *dev)

0 commit comments

Comments
 (0)