Skip to content

Commit 33fab68

Browse files
committed
transport: ble_gatt: add Kconfig selection for LESC / AUTHEN
Introduce Kconfig option for required GATT permissions. Provide 2 options: * LE Secure Connection * Authentication (with encryption) This makes sure that proper BT Security Level is reached before trying being able to access pouch characteristics. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent e7c36c2 commit 33fab68

File tree

7 files changed

+23
-5
lines changed

7 files changed

+23
-5
lines changed

src/transport/gatt/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ config POUCH_TRANSPORT_GATT_CUD_ATTRIBUTES
1010
can be useful during debugging and development to identify
1111
the characteristics without consulting their UUIDs.
1212

13+
choice POUCH_TRANSPORT_GATT_PERM
14+
bool "GATT permissions"
15+
16+
config POUCH_TRANSPORT_GATT_PERM_LESC
17+
bool "Require LE Secure Connection for access"
18+
19+
config POUCH_TRANSPORT_GATT_PERM_AUTHEN
20+
bool "Require authentication for access"
21+
22+
endchoice # POUCH_TRANSPORT_GATT_PERM
23+
1324
module = POUCH_GATT
1425
module-str = Pouch GATT
1526
source "subsys/logging/Kconfig.template.log_config"

src/transport/gatt/device_cert_characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static ssize_t device_cert_read(struct bt_conn *conn,
9797
POUCH_GATT_CHARACTERISTIC(device_cert,
9898
(const struct bt_uuid *) &pouch_gatt_device_cert_chrc_uuid,
9999
BT_GATT_CHRC_READ,
100-
BT_GATT_PERM_READ_LESC,
100+
POUCH_GATT_PERM_READ,
101101
device_cert_read,
102102
NULL,
103103
&device_cert_chrc_ctx);

src/transport/gatt/downlink_characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ssize_t downlink_write(struct bt_conn *conn,
5252
POUCH_GATT_CHARACTERISTIC(downlink,
5353
(const struct bt_uuid *) &pouch_gatt_downlink_chrc_uuid,
5454
BT_GATT_CHRC_WRITE,
55-
BT_GATT_PERM_WRITE_LESC,
55+
POUCH_GATT_PERM_WRITE,
5656
NULL,
5757
downlink_write,
5858
NULL);

src/transport/gatt/info_characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static ssize_t info_read(struct bt_conn *conn,
124124
POUCH_GATT_CHARACTERISTIC(info,
125125
(const struct bt_uuid *) &pouch_gatt_info_chrc_uuid,
126126
BT_GATT_CHRC_READ,
127-
BT_GATT_PERM_READ_LESC,
127+
POUCH_GATT_PERM_READ,
128128
info_read,
129129
NULL,
130130
&info_chrc_ctx);

src/transport/gatt/pouch_gatt_declarations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@
3838
STRUCT_SECTION_START_EXTERN(bt_gatt_attr);
3939
#define POUCH_GATT_ATTR_ARRAY_PTR STRUCT_SECTION_START(bt_gatt_attr)
4040
#define POUCH_GATT_ATTR_ARRAY_LEN(dst) STRUCT_SECTION_COUNT(bt_gatt_attr, dst)
41+
42+
#define POUCH_GATT_PERM_READ \
43+
(IS_ENABLED(CONFIG_POUCH_TRANSPORT_GATT_PERM_AUTHEN) ? BT_GATT_PERM_READ_AUTHEN \
44+
: BT_GATT_PERM_READ_LESC)
45+
#define POUCH_GATT_PERM_WRITE \
46+
(IS_ENABLED(CONFIG_POUCH_TRANSPORT_GATT_PERM_AUTHEN) ? BT_GATT_PERM_WRITE_AUTHEN \
47+
: BT_GATT_PERM_WRITE_LESC)

src/transport/gatt/server_cert_characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static ssize_t server_cert_write(struct bt_conn *conn,
153153
POUCH_GATT_CHARACTERISTIC(server_cert,
154154
(const struct bt_uuid *) &pouch_gatt_server_cert_chrc_uuid,
155155
BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
156-
BT_GATT_PERM_READ_LESC | BT_GATT_PERM_WRITE_LESC,
156+
POUCH_GATT_PERM_READ | POUCH_GATT_PERM_WRITE,
157157
server_cert_serial_read,
158158
server_cert_write,
159159
&server_cert_chrc_ctx);

src/transport/gatt/uplink_characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static void uplink_indicate_destroy(struct bt_gatt_indicate_params *params)
198198
POUCH_GATT_CHARACTERISTIC(uplink,
199199
(const struct bt_uuid *) &pouch_gatt_uplink_chrc_uuid,
200200
BT_GATT_CHRC_READ | BT_GATT_CHRC_INDICATE,
201-
BT_GATT_PERM_READ_LESC,
201+
POUCH_GATT_PERM_READ,
202202
uplink_read,
203203
NULL,
204204
&uplink_chrc_ctx);

0 commit comments

Comments
 (0)