input: hog: Attempt to set security level if not bonded
Luiz Augusto von Dentz
maintainerPATCH v2 1/2 input: hog: Attempt to set security level if not bonded
From: Luiz Augusto von Dentz <[email protected]>
This attempts to set the security if the device is not bonded, the kernel will block any communication on the ATT socket while bumping the security and if that fails the device will be disconnected which is better than having the device dangling around without being able to communicate with it until it is properly bonded.
--- profiles/input/hog.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
profiles/input/hog.c +11 -2
@@ -49,6 +49,8 @@#include "src/shared/util.h" #include "src/shared/uhid.h" #include "src/shared/queue.h" +#include "src/shared/att.h" +#include "src/shared/gatt-client.h" #include "src/plugin.h" #include "suspend.h"
@@ -187,8 +189,15 @@ static int hog_accept(struct btd_service *service) }/* HOGP 1.0 Section 6.1 requires bonding */ -if (!device_is_bonded (device,btd_device_get_bdaddr_type (device))) -return -ECONNREFUSED ; +if (!device_is_bonded (device,btd_device_get_bdaddr_type (device))) { +struct bt_gatt_client *client; + + client =btd_device_get_gatt_client (device); +if (!bt_gatt_client_set_security (client, +BT_ATT_SECURITY_MEDIUM )) { +return -ECONNREFUSED ; + } + }/* TODO: Replace GAttrib with bt_gatt_client */ bt_hog_attach (dev->hog, attrib);
Signature · 1 line
2.21.1
Luiz Augusto von Dentz
maintainerPATCH v2 2/2 input: Add LEAudioSecurity setting to input.conf
From: Luiz Augusto von Dentz <[email protected]>
LEAudioSecurity can be used to enable/disable automatic upgrades of security for LE devices, by default it is enabled so existing devices that did not require security and were not bonded will automatically upgrade the security.
Note: Platforms disabling this setting would require users to manually bond the device which may require changes to the user interface to always force bonding for input devices ad APIs such as Device.Connect directly will no longer work which maybe perceived as a regression.
--- profiles/input/device.h | 1 + profiles/input/hog.c | 13 +++++++++++-- profiles/input/input.conf | 5 +++++ profiles/input/manager.c | 11 ++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-)
profiles/input/device.h +1 -0
@@ -30,6 +30,7 @@ struct input_conn;void input_set_idle_timeout (int timeout);void input_enable_userspace_hid (bool state);void input_set_classic_bonded_only (bool state); +void input_set_auto_sec (bool state);int input_device_register (struct btd_service *service);void input_device_unregister (struct btd_service *service);
profiles/input/hog.c +11 -2
@@ -53,6 +53,7 @@#include "src/shared/gatt-client.h" #include "src/plugin.h" +#include "device.h" #include "suspend.h" #include "attrib/att.h" #include "attrib/gattrib.h"
@@ -67,8 +68,14 @@ struct hog_device { };static gboolean suspend_supported = FALSE; +static bool auto_sec = true;static struct queue *devices =NULL ; +void input_set_auto_sec (bool state) +{ + auto_sec = state; +} +static void hog_device_accept (struct hog_device *dev,struct gatt_db *db) {char name[248 ];
@@ -192,11 +199,13 @@ static int hog_accept(struct btd_service *service)if (!device_is_bonded (device,btd_device_get_bdaddr_type (device))) {struct bt_gatt_client *client; +if (!auto_sec) +return -ECONNREFUSED ; + client =btd_device_get_gatt_client (device);if (!bt_gatt_client_set_security (client, -BT_ATT_SECURITY_MEDIUM )) { +BT_ATT_SECURITY_MEDIUM ))return -ECONNREFUSED ; - } }/* TODO: Replace GAttrib with bt_gatt_client */
profiles/input/input.conf +5 -0
@@ -19,3 +19,8 @@ # pairing/encryption. # Defaults to false to maximize device compatibility. #ClassicBondedOnly=true + +# LE upgrade security +# Enables upgrades of security automatically if required. +# Defaults to true to maximize device compatibility. +#LEAutoSecurity=true
profiles/input/manager.c +10 -1
@@ -96,7 +96,7 @@ static int input_init(void) config =load_config_file (CONFIGDIR "/input.conf" );if (config) {int idle_timeout; -gboolean uhid_enabled, classic_bonded_only; +gboolean uhid_enabled, classic_bonded_only, auto_sec; idle_timeout =g_key_file_get_integer (config,"General" ,"IdleTimeout" , &err);
@@ -125,6 +125,15 @@ static int input_init(void) }else g_clear_error (&err); + auto_sec =g_key_file_get_boolean (config,"General" , +"LEAutoSecurity" , &err); +if (!err) { +DBG ("input.conf: LEAutoSecurity=%s" , + auto_sec ?"true" :"false" ); +input_set_auto_sec (auto_sec); + }else +g_clear_error (&err); + }btd_profile_register (&input_profile);
Signature · 1 line
2.21.1
Luiz Augusto von Dentz
maintainerRe: [PATCH v2 2/2] input: Add LEAudioSecurity setting to input.conf
Hi Alain,
Quoted 8 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
LEAudioSecurity can be used to enable/disable automatic upgrades of security for LE devices, by default it is enabled so existing devices that did not require security and were not bonded will automatically upgrade the security.
Quoted 4 lines
Note: Platforms disabling this setting would require users to manually bond the device which may require changes to the user interface to always force bonding for input devices ad APIs such as Device.Connect directly will no longer work which maybe perceived as a regression.
Does this attends your requirements?
Quoted 107 lines
--- profiles/input/device.h | 1 + profiles/input/hog.c | 13 +++++++++++-- profiles/input/input.conf | 5 +++++ profiles/input/manager.c | 11 ++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-)profiles/input/device.h +1
-0@@ -30,6 +30,7 @@ struct input_conn;void input_set_idle_timeout (int timeout);void input_enable_userspace_hid (bool state);void input_set_classic_bonded_only (bool state); +void input_set_auto_sec (bool state);int input_device_register (struct btd_service *service);void input_device_unregister (struct btd_service *service);profiles/input/hog.c +11
-2@@ -53,6 +53,7 @@#include "src/shared/gatt-client.h" #include "src/plugin.h" +#include "device.h" #include "suspend.h" #include "attrib/att.h" #include "attrib/gattrib.h" @@ -67,8 +68,14 @@ struct hog_device { };static gboolean suspend_supported = FALSE; +static bool auto_sec = true;static struct queue *devices =NULL ; +void input_set_auto_sec (bool state) +{ + auto_sec = state; +} +static void hog_device_accept (struct hog_device *dev,struct gatt_db *db) {char name[248 ];@@ -192,11 +199,13 @@ static int hog_accept(struct btd_service *service)if (!device_is_bonded (device,btd_device_get_bdaddr_type (device))) {struct bt_gatt_client *client; +if (!auto_sec) +return -ECONNREFUSED ; + client =btd_device_get_gatt_client (device);if (!bt_gatt_client_set_security (client, -BT_ATT_SECURITY_MEDIUM )) { +BT_ATT_SECURITY_MEDIUM ))return -ECONNREFUSED ; - } }/* TODO: Replace GAttrib with bt_gatt_client */ profiles/input/input.conf +5
-0@@ -19,3 +19,8 @@ # pairing/encryption. # Defaults to false to maximize device compatibility. #ClassicBondedOnly=true + +# LE upgrade security +# Enables upgrades of security automatically if required. +# Defaults to true to maximize device compatibility. +#LEAutoSecurity=trueprofiles/input/manager.c +10
-2@@ -96,7 +96,7 @@ static int input_init(void) config =load_config_file (CONFIGDIR "/input.conf" );if (config) {int idle_timeout; -gboolean uhid_enabled, classic_bonded_only; +gboolean uhid_enabled, classic_bonded_only, auto_sec; idle_timeout =g_key_file_get_integer (config,"General" ,"IdleTimeout" , &err);@@ -125,6 +125,15 @@ static int input_init(void) }else g_clear_error (&err); + auto_sec =g_key_file_get_boolean (config,"General" , +"LEAutoSecurity" , &err); +if (!err) { +DBG ("input.conf: LEAutoSecurity=%s" , + auto_sec ?"true" :"false" ); +input_set_auto_sec (auto_sec); + }else +g_clear_error (&err); + }btd_profile_register (&input_profile); --2.21.1
Signature · 1 line
Luiz Augusto von Dentz
Marcel Holtmann
maintainerRe: [PATCH v2 2/2] input: Add LEAudioSecurity setting to input.conf
In reply to Luiz Augusto von DentzHi Luiz,
Quoted 4 lines
LEAudioSecurity can be used to enable/disable automatic upgrades of security for LE devices, by default it is enabled so existing devices that did not require security and were not bonded will automatically upgrade the security.
LEAudioSecurity?
Regards
Marcel
Luiz Augusto von Dentz
maintainerRe: [PATCH v2 2/2] input: Add LEAudioSecurity setting to input.conf
Hi Marcel,
Quoted 9 lines · Marcel Holtmann
Hi Luiz,
Quoted 4 lines
LEAudioSecurity can be used to enable/disable automatic upgrades of security for LE devices, by default it is enabled so existing devices that did not require security and were not bonded will automatically upgrade the security.
LEAudioSecurity?
Derr, will fix it, luckly it is just in the commit message the option is actually LEAutoSecurity.
Signature · 1 line
Luiz Augusto von Dentz