input: avoid NSP1 disconnects caused by Sniff/Exit Sniff churn
PATCH 2/2 profiles/input: disable force-active for Nintendo Switch Pro v1
In reply to Frédéric DanisFor Nintendo Switch Pro v1 controllers (VID:PID 057e:2009), set BT_IO_OPT_FORCE_ACTIVE to BT_POWER_FORCE_ACTIVE_OFF on the HID interrupt channel during connection setup.
This avoids repeated host-triggered Exit Sniff requests and reduces Sniff/Exit Sniff churn linked to unexpected disconnects.
--- profiles/input/device.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
profiles/input/device.c +16 -0
@@ -1065,6 +1065,9 @@ static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition,return FALSE; } +#define NINTENDO_VENDOR_ID 0x057e +#define NINTENDO_PRO_CONTROLLER_PID 0x2009 +static int hidp_add_connection (struct input_device *idev) {struct hidp_connadd_req *req;
@@ -1101,6 +1104,19 @@ static int hidp_add_connection(struct input_device *idev) goto cleanup; } +if ((req->vendor ==NINTENDO_VENDOR_ID ) && + (req->product ==NINTENDO_PRO_CONTROLLER_PID )) { +if (!bt_io_set (idev->intr_io, &gerr, +BT_IO_OPT_FORCE_ACTIVE , +BT_POWER_FORCE_ACTIVE_OFF , +BT_IO_OPT_INVALID )) { +error ("btio: %s" , gerr->message); +g_error_free (gerr); + err = -EFAULT ; + goto cleanup; + } + } +/* Encryption is mandatory for keyboards */ /* Some platforms may choose to require encryption for all devices */ /* Note that this only matters for pre 2.1 devices as otherwise the */
Signature · 1 line
2.43.0
cover input: avoid NSP1 disconnects caused by Sniff/Exit Sniff churn
We received reports of Bluetooth instability with Nintendo Switch Pro v1 (NSP1), including unexpected disconnects during use. HCI traces indicate the controller repeatedly requests Sniff mode while BlueZ keeps forcing Active mode, creating frequent Sniff/Exit Sniff transitions and increasing the chance of LMP Sniff Response failures.
This series adds generic btio support to control force-active behavior for L2CAP sockets, then uses it in the input profile for NSP1 by disabling force-active on the HID interrupt channel. With that, BlueZ stops repeatedly issuing Exit Sniff requests for this device, improving connection stability.
Frédéric Danis (2):
btio: add BT_IO_OPT_FORCE_ACTIVE support for L2CAP sockets profiles/input: disable force-active for Nintendo Switch Pro v1
btio/btio.c | 35 +++++++++++++++++++++++++++++++---- btio/btio.h | 1 + profiles/input/device.c | 16 ++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 btio: add BT_IO_OPT_FORCE_ACTIVE support for L2CAP sockets
Introduce BT_IO_OPT_FORCE_ACTIVE in btio and plumb it through option parsing and L2CAP setup.
When set, btio now programs BT_POWER on the underlying socket, allowing callers to explicitly control force-active behavior.
--- btio/btio.c | 35 +++++++++++++++++++++++++++++++---- btio/btio.h | 1 + 2 files changed, 32 insertions(+), 4 deletions(-)
btio/btio.c +31 -4
@@ -68,6 +68,7 @@ struct set_opts {int central;uint8_t mode;int flushable; +int force_active;uint32_t priority;uint16_t voice;struct bt_iso_qos qos;
@@ -601,6 +602,17 @@ static int l2cap_set_flushable(int sock, gboolean flushable)return 0 ; } +static int l2cap_set_bt_power (int sock,int force_active) +{ +struct bt_power pwr = {0 }; + + pwr.force_active = force_active; +if (setsockopt (sock,SOL_BLUETOOTH ,BT_POWER , &pwr,sizeof (pwr)) <0 ) +return -errno; + +return 0 ; +} +static int set_priority (int sock,uint32_t prio) {if (setsockopt (sock,SOL_SOCKET ,SO_PRIORITY , &prio,sizeof (prio)) <0 )
@@ -696,8 +708,8 @@ static gboolean set_le_mode(int sock, uint8_t mode, GError **err)static gboolean l2cap_set (int sock,uint8_t src_type,int sec_level,int imtu,uint16_t omtu,uint8_t mode, -int central,int flushable,uint32_t priority, -GError **err) +int central,int flushable,int force_active, +uint32_t priority,GError **err) {if (imtu !=-1 || omtu || mode) {gboolean ret = FALSE;
@@ -736,6 +748,11 @@ static gboolean l2cap_set(int sock, uint8_t src_type, int sec_level,return FALSE; } +if (force_active >=0 &&l2cap_set_bt_power (sock, force_active) <0 ) { +ERROR_FAILED (err,"l2cap_set_bt_power" , errno); +return FALSE; + } +if (priority >0 &&set_priority (sock, priority) <0 ) {ERROR_FAILED (err,"set_priority" , errno);return FALSE;
@@ -968,6 +985,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err, opts->central =-1 ; opts->mode =L2CAP_MODE_BASIC ; opts->flushable =-1 ; + opts->force_active =-1 ; opts->priority =0 ; opts->src_type =BDADDR_BREDR ; opts->dst_type =BDADDR_BREDR ;
@@ -1043,6 +1061,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,case BT_IO_OPT_FLUSHABLE : opts->flushable =va_arg (args, gboolean);break ; +case BT_IO_OPT_FORCE_ACTIVE : + opts->force_active =va_arg (args, int); +break ;case BT_IO_OPT_PRIORITY : opts->priority =va_arg (args, int);break ;
@@ -1387,6 +1408,7 @@ parse_opts:case BT_IO_OPT_SOURCE_CHANNEL :case BT_IO_OPT_DEST_CHANNEL :case BT_IO_OPT_MTU : +case BT_IO_OPT_FORCE_ACTIVE :case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :case BT_IO_OPT_BASE :
@@ -1544,6 +1566,7 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1,case BT_IO_OPT_IMTU :case BT_IO_OPT_MODE :case BT_IO_OPT_FLUSHABLE : +case BT_IO_OPT_FORCE_ACTIVE :case BT_IO_OPT_PRIORITY :case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :
@@ -1658,6 +1681,7 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args)case BT_IO_OPT_CENTRAL :case BT_IO_OPT_MODE :case BT_IO_OPT_FLUSHABLE : +case BT_IO_OPT_FORCE_ACTIVE :case BT_IO_OPT_PRIORITY :case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :
@@ -1795,6 +1819,7 @@ static gboolean iso_get(int sock, GError **err, BtIOOption opt1, va_list args)case BT_IO_OPT_CENTRAL :case BT_IO_OPT_MODE :case BT_IO_OPT_FLUSHABLE : +case BT_IO_OPT_FORCE_ACTIVE :case BT_IO_OPT_PRIORITY :case BT_IO_OPT_VOICE :case BT_IO_OPT_ISO_BC_NUM_BIS :
@@ -1963,7 +1988,8 @@ gboolean bt_io_set(GIOChannel *io, GError **err, BtIOOption opt1, ...)case BT_IO_L2CAP :return l2cap_set (sock, opts.src_type, opts.sec_level, opts.imtu, opts.omtu, opts.mode, opts.central, - opts.flushable, opts.priority, err); + opts.flushable, opts.force_active, + opts.priority, err);case BT_IO_RFCOMM :return rfcomm_set (sock, opts.sec_level, opts.central, err);case BT_IO_SCO :
@@ -2014,7 +2040,8 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts, goto failed;if (!l2cap_set (sock, opts->src_type, opts->sec_level, opts->imtu, opts->omtu, opts->mode, - opts->central, opts->flushable, opts->priority, + opts->central, opts->flushable, + opts->force_active, opts->priority, err)) goto failed;break ;
btio/btio.h +1 -0
@@ -42,6 +42,7 @@ typedef enum {BT_IO_OPT_CLASS ,BT_IO_OPT_MODE ,BT_IO_OPT_FLUSHABLE , +BT_IO_OPT_FORCE_ACTIVE ,BT_IO_OPT_PRIORITY ,BT_IO_OPT_VOICE , BT_IO_OPT_PHY,
Signature · 1 line
2.43.0
Luiz Augusto von Dentz
maintainerHi Frédéric,
Quoted 6 lines · Frédéric Danis
We received reports of Bluetooth instability with Nintendo Switch Pro v1 (NSP1), including unexpected disconnects during use. HCI traces indicate the controller repeatedly requests Sniff mode while BlueZ keeps forcing Active mode, creating frequent Sniff/Exit Sniff transitions and increasing the chance of LMP Sniff Response failures.
Interesting, but we should only exit sniff mode if we are going to transmit, right? Or do we exit upon receiving something? Maybe we should track who initiated sniff mode, if it was the remote initiated it, then we shouldn't exit it.
Quoted 19 lines
This series adds generic btio support to control force-active behavior for L2CAP sockets, then uses it in the input profile for NSP1 by disabling force-active on the HID interrupt channel. With that, BlueZ stops repeatedly issuing Exit Sniff requests for this device, improving connection stability.
Frédéric Danis (2):
btio: addBT_IO_OPT_FORCE_ACTIVEsupport for L2CAP sockets profiles/input: disable force-active for Nintendo Switch Pro v1btio/btio.c | 35 +++++++++++++++++++++++++++++++---- btio/btio.h | 1 + profiles/input/device.c | 16 ++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)--
2.43.0
Signature · 1 line
Luiz Augusto von Dentz
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1152198
---Test result---
Test Summary:
CheckPatch PASS 0.63 seconds GitLint PASS 0.40 seconds BuildEll PASS 20.36 seconds BluezMake PASS 597.60 seconds MakeCheck PASS 19.56 seconds MakeDistcheck PASS 159.04 seconds CheckValgrind PASS 229.06 seconds CheckSmatch PASS 312.41 seconds bluezmakeextell PASS 103.17 seconds IncrementalBuild PASS 601.76 seconds ScanBuild PASS 1014.94 seconds
https://github.com/bluez/bluez/pull/2438
---
Regards,
Linux Bluetooth