Skip to content

Commit 5b232bf

Browse files
sjancdleach02
authored andcommitted
Bluetooth: GATT: Allow to tune writable device appearance permissions
This allows to select if device appearance requires encryption or authentication or none. This makes it similar to what is implemented for device name characteristic. Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
1 parent 398487f commit 5b232bf

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

subsys/bluetooth/host/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,10 +871,6 @@ config BT_DEVICE_APPEARANCE_DYNAMIC
871871
Enables use of bt_set_appearance.
872872
If CONFIG_BT_SETTINGS is set, the appearance is persistently stored.
873873

874-
config BT_DEVICE_APPEARANCE_GATT_WRITABLE
875-
bool "Allow authenticated peers to set GAP Appearance"
876-
depends on BT_DEVICE_APPEARANCE_DYNAMIC
877-
878874
config BT_DEVICE_APPEARANCE
879875
int "Bluetooth device appearance"
880876
range 0 $(UINT16_MAX)

subsys/bluetooth/host/Kconfig.gatt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,34 @@ config DEVICE_NAME_GATT_WRITABLE_AUTHEN
287287
endchoice #BT_DEVICE_NAME_GATT_WRITABLE_SECURITY
288288
endif #BT_DEVICE_NAME_GATT_WRITABLE
289289

290+
config BT_DEVICE_APPEARANCE_GATT_WRITABLE
291+
bool "Allow to write GAP Appearance by remote GATT clients"
292+
depends on BT_DEVICE_APPEARANCE_DYNAMIC
293+
default y
294+
help
295+
Enabling this option allows remote GATT clients to write to device
296+
appearance GAP characteristic.
297+
298+
if BT_DEVICE_APPEARANCE_GATT_WRITABLE
299+
choice BT_DEVICE_APPEARANCE_GATT_WRITABLE
300+
prompt "Security requirements"
301+
default DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN
302+
help
303+
Select security requirementsf for writing device name by remote GATT
304+
clients.
305+
306+
config BT_DEVICE_APPEARANCE_GATT_WRITABLE_NONE
307+
bool "No requirements"
308+
309+
config BT_DEVICE_APPEARANCE_GATT_WRITABLE_ENCRYPT
310+
bool "Encryption required"
311+
312+
config DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN
313+
bool "Encryption and authentication required"
314+
315+
endchoice #BT_DEVICE_APPEARANCE_GATT_WRITABLE
316+
endif #BT_DEVICE_APPEARANCE_GATT_WRITABLE
317+
290318
config BT_GATT_AUTHORIZATION_CUSTOM
291319
bool "Custom authorization of GATT operations"
292320
help

subsys/bluetooth/host/gatt.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,15 @@ static ssize_t write_appearance(struct bt_conn *conn, const struct bt_gatt_attr
174174
}
175175
#endif /* CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE */
176176

177-
#if CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE
177+
#if defined(CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE)
178178
#define GAP_APPEARANCE_PROPS (BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE)
179+
#if defined(CONFIG_DEVICE_APPEARANCE_GATT_WRITABLE_AUTHEN)
179180
#define GAP_APPEARANCE_PERMS (BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_AUTHEN)
181+
#elif defined(CONFIG_BT_DEVICE_APPEARANCE_GATT_WRITABLE_ENCRYPT)
182+
#define GAP_APPEARANCE_PERMS (BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT)
183+
#else
184+
#define GAP_APPEARANCE_PERMS (BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)
185+
#endif
180186
#define GAP_APPEARANCE_WRITE_HANDLER write_appearance
181187
#else
182188
#define GAP_APPEARANCE_PROPS BT_GATT_CHRC_READ

0 commit comments

Comments
 (0)