linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Bluetooth: rfcomm: fix modem control handling
@ 2025-10-23 12:05 Johan Hovold
  2025-10-23 12:51 ` [v2] " bluez.test.bot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Johan Hovold @ 2025-10-23 12:05 UTC (permalink / raw)
  To: Luiz Augusto von Dentz, Marcel Holtmann, Johan Hedberg
  Cc: linux-bluetooth, linux-kernel, Johan Hovold, stable

The RFCOMM driver confuses the local and remote modem control signals,
which specifically means that the reported DTR and RTS state will
instead reflect the remote end (i.e. DSR and CTS).

This issue dates back to the original driver (and a follow-on update)
merged in 2002, which resulted in a non-standard implementation of
TIOCMSET that allowed controlling also the TS07.10 IC and DV signals by
mapping them to the RI and DCD input flags, while TIOCMGET failed to
return the actual state of DTR and RTS.

Note that the bogus control of input signals in tiocmset() is just
dead code as those flags will have been masked out by the tty layer
since 2003.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
---

Changes in v2
 - fix a compilation issue discovered before sending v1 but never folded
   into the actual patch...


 net/bluetooth/rfcomm/tty.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 376ce6de84be..b783526ab588 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -643,8 +643,8 @@ static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig)
 		tty_port_tty_hangup(&dev->port, true);
 
 	dev->modem_status =
-		((v24_sig & RFCOMM_V24_RTC) ? (TIOCM_DSR | TIOCM_DTR) : 0) |
-		((v24_sig & RFCOMM_V24_RTR) ? (TIOCM_RTS | TIOCM_CTS) : 0) |
+		((v24_sig & RFCOMM_V24_RTC) ? TIOCM_DSR : 0) |
+		((v24_sig & RFCOMM_V24_RTR) ? TIOCM_CTS : 0) |
 		((v24_sig & RFCOMM_V24_IC)  ? TIOCM_RI : 0) |
 		((v24_sig & RFCOMM_V24_DV)  ? TIOCM_CD : 0);
 }
@@ -1055,10 +1055,14 @@ static void rfcomm_tty_hangup(struct tty_struct *tty)
 static int rfcomm_tty_tiocmget(struct tty_struct *tty)
 {
 	struct rfcomm_dev *dev = tty->driver_data;
+	struct rfcomm_dlc *dlc = dev->dlc;
+	u8 v24_sig;
 
 	BT_DBG("tty %p dev %p", tty, dev);
 
-	return dev->modem_status;
+	rfcomm_dlc_get_modem_status(dlc, &v24_sig);
+
+	return (v24_sig & (TIOCM_DTR | TIOCM_RTS)) | dev->modem_status;
 }
 
 static int rfcomm_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
@@ -1071,23 +1075,15 @@ static int rfcomm_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigne
 
 	rfcomm_dlc_get_modem_status(dlc, &v24_sig);
 
-	if (set & TIOCM_DSR || set & TIOCM_DTR)
+	if (set & TIOCM_DTR)
 		v24_sig |= RFCOMM_V24_RTC;
-	if (set & TIOCM_RTS || set & TIOCM_CTS)
+	if (set & TIOCM_RTS)
 		v24_sig |= RFCOMM_V24_RTR;
-	if (set & TIOCM_RI)
-		v24_sig |= RFCOMM_V24_IC;
-	if (set & TIOCM_CD)
-		v24_sig |= RFCOMM_V24_DV;
 
-	if (clear & TIOCM_DSR || clear & TIOCM_DTR)
+	if (clear & TIOCM_DTR)
 		v24_sig &= ~RFCOMM_V24_RTC;
-	if (clear & TIOCM_RTS || clear & TIOCM_CTS)
+	if (clear & TIOCM_RTS)
 		v24_sig &= ~RFCOMM_V24_RTR;
-	if (clear & TIOCM_RI)
-		v24_sig &= ~RFCOMM_V24_IC;
-	if (clear & TIOCM_CD)
-		v24_sig &= ~RFCOMM_V24_DV;
 
 	rfcomm_dlc_set_modem_status(dlc, v24_sig);
 
-- 
2.49.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [v2] Bluetooth: rfcomm: fix modem control handling
  2025-10-23 12:05 [PATCH v2] Bluetooth: rfcomm: fix modem control handling Johan Hovold
@ 2025-10-23 12:51 ` bluez.test.bot
  2025-10-23 21:40 ` [PATCH v2] " patchwork-bot+bluetooth
  2025-10-29 20:15 ` Paul Menzel
  2 siblings, 0 replies; 5+ messages in thread
From: bluez.test.bot @ 2025-10-23 12:51 UTC (permalink / raw)
  To: linux-bluetooth, johan

[-- Attachment #1: Type: text/plain, Size: 2538 bytes --]

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=1014980

---Test result---

Test Summary:
CheckPatch                    PENDING   0.56 seconds
GitLint                       PENDING   0.34 seconds
SubjectPrefix                 PASS      0.07 seconds
BuildKernel                   PASS      26.60 seconds
CheckAllWarning               PASS      27.39 seconds
CheckSparse                   PASS      30.70 seconds
BuildKernel32                 PASS      24.50 seconds
TestRunnerSetup               PASS      489.96 seconds
TestRunner_l2cap-tester       PASS      24.18 seconds
TestRunner_iso-tester         PASS      102.68 seconds
TestRunner_bnep-tester        PASS      6.05 seconds
TestRunner_mgmt-tester        FAIL      117.24 seconds
TestRunner_rfcomm-tester      PASS      9.33 seconds
TestRunner_sco-tester         PASS      14.40 seconds
TestRunner_ioctl-tester       PASS      11.28 seconds
TestRunner_mesh-tester        FAIL      11.43 seconds
TestRunner_smp-tester         PASS      8.48 seconds
TestRunner_userchan-tester    PASS      6.38 seconds
IncrementalBuild              PENDING   0.60 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 490, Passed: 482 (98.4%), Failed: 4, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.105 seconds
LL Privacy - Add Device 2 (2 Devices to AL)          Failed       0.171 seconds
LL Privacy - Add Device 3 (AL is full)               Failed       0.191 seconds
LL Privacy - Set Device Flag 1 (Device Privacy)      Failed       0.157 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    1.792 seconds
Mesh - Send cancel - 2                               Timed out    1.994 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Bluetooth: rfcomm: fix modem control handling
  2025-10-23 12:05 [PATCH v2] Bluetooth: rfcomm: fix modem control handling Johan Hovold
  2025-10-23 12:51 ` [v2] " bluez.test.bot
@ 2025-10-23 21:40 ` patchwork-bot+bluetooth
  2025-10-29 20:15 ` Paul Menzel
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+bluetooth @ 2025-10-23 21:40 UTC (permalink / raw)
  To: Johan Hovold
  Cc: luiz.dentz, marcel, johan.hedberg, linux-bluetooth, linux-kernel,
	stable

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Thu, 23 Oct 2025 14:05:30 +0200 you wrote:
> The RFCOMM driver confuses the local and remote modem control signals,
> which specifically means that the reported DTR and RTS state will
> instead reflect the remote end (i.e. DSR and CTS).
> 
> This issue dates back to the original driver (and a follow-on update)
> merged in 2002, which resulted in a non-standard implementation of
> TIOCMSET that allowed controlling also the TS07.10 IC and DV signals by
> mapping them to the RI and DCD input flags, while TIOCMGET failed to
> return the actual state of DTR and RTS.
> 
> [...]

Here is the summary with links:
  - [v2] Bluetooth: rfcomm: fix modem control handling
    https://git.kernel.org/bluetooth/bluetooth-next/c/8d2c47aeb078

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Bluetooth: rfcomm: fix modem control handling
  2025-10-23 12:05 [PATCH v2] Bluetooth: rfcomm: fix modem control handling Johan Hovold
  2025-10-23 12:51 ` [v2] " bluez.test.bot
  2025-10-23 21:40 ` [PATCH v2] " patchwork-bot+bluetooth
@ 2025-10-29 20:15 ` Paul Menzel
  2025-10-30 13:27   ` Johan Hovold
  2 siblings, 1 reply; 5+ messages in thread
From: Paul Menzel @ 2025-10-29 20:15 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Luiz Augusto von Dentz, Marcel Holtmann, Johan Hedberg,
	linux-bluetooth, linux-kernel, stable

Dear Johan,


Thank you for your patch.


Am 23.10.25 um 14:05 schrieb Johan Hovold:
> The RFCOMM driver confuses the local and remote modem control signals,
> which specifically means that the reported DTR and RTS state will
> instead reflect the remote end (i.e. DSR and CTS).
> 
> This issue dates back to the original driver (and a follow-on update)
> merged in 2002, which resulted in a non-standard implementation of
> TIOCMSET that allowed controlling also the TS07.10 IC and DV signals by
> mapping them to the RI and DCD input flags, while TIOCMGET failed to
> return the actual state of DTR and RTS.
> 
> Note that the bogus control of input signals in tiocmset() is just
> dead code as those flags will have been masked out by the tty layer
> since 2003.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")

There is a linux-history git archive [1], if somebody wants dig further. 
But not relevant for the tag used by the stable folks.

Is there any way to test your change, to read DTR and RTS state?

> Cc: stable@vger.kernel.org
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> 
> Changes in v2
>   - fix a compilation issue discovered before sending v1 but never folded
>     into the actual patch...
> 
> 
>   net/bluetooth/rfcomm/tty.c | 26 +++++++++++---------------
>   1 file changed, 11 insertions(+), 15 deletions(-)
> 
> diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
> index 376ce6de84be..b783526ab588 100644
> --- a/net/bluetooth/rfcomm/tty.c
> +++ b/net/bluetooth/rfcomm/tty.c
> @@ -643,8 +643,8 @@ static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig)
>   		tty_port_tty_hangup(&dev->port, true);
>   
>   	dev->modem_status =
> -		((v24_sig & RFCOMM_V24_RTC) ? (TIOCM_DSR | TIOCM_DTR) : 0) |
> -		((v24_sig & RFCOMM_V24_RTR) ? (TIOCM_RTS | TIOCM_CTS) : 0) |
> +		((v24_sig & RFCOMM_V24_RTC) ? TIOCM_DSR : 0) |
> +		((v24_sig & RFCOMM_V24_RTR) ? TIOCM_CTS : 0) |
>   		((v24_sig & RFCOMM_V24_IC)  ? TIOCM_RI : 0) |
>   		((v24_sig & RFCOMM_V24_DV)  ? TIOCM_CD : 0);
>   }
> @@ -1055,10 +1055,14 @@ static void rfcomm_tty_hangup(struct tty_struct *tty)
>   static int rfcomm_tty_tiocmget(struct tty_struct *tty)
>   {
>   	struct rfcomm_dev *dev = tty->driver_data;
> +	struct rfcomm_dlc *dlc = dev->dlc;
> +	u8 v24_sig;
>   
>   	BT_DBG("tty %p dev %p", tty, dev);
>   
> -	return dev->modem_status;
> +	rfcomm_dlc_get_modem_status(dlc, &v24_sig);
> +
> +	return (v24_sig & (TIOCM_DTR | TIOCM_RTS)) | dev->modem_status;
>   }
>   
>   static int rfcomm_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
> @@ -1071,23 +1075,15 @@ static int rfcomm_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigne
>   
>   	rfcomm_dlc_get_modem_status(dlc, &v24_sig);
>   
> -	if (set & TIOCM_DSR || set & TIOCM_DTR)
> +	if (set & TIOCM_DTR)
>   		v24_sig |= RFCOMM_V24_RTC;
> -	if (set & TIOCM_RTS || set & TIOCM_CTS)
> +	if (set & TIOCM_RTS)
>   		v24_sig |= RFCOMM_V24_RTR;
> -	if (set & TIOCM_RI)
> -		v24_sig |= RFCOMM_V24_IC;
> -	if (set & TIOCM_CD)
> -		v24_sig |= RFCOMM_V24_DV;
>   
> -	if (clear & TIOCM_DSR || clear & TIOCM_DTR)
> +	if (clear & TIOCM_DTR)
>   		v24_sig &= ~RFCOMM_V24_RTC;
> -	if (clear & TIOCM_RTS || clear & TIOCM_CTS)
> +	if (clear & TIOCM_RTS)
>   		v24_sig &= ~RFCOMM_V24_RTR;
> -	if (clear & TIOCM_RI)
> -		v24_sig &= ~RFCOMM_V24_IC;
> -	if (clear & TIOCM_CD)
> -		v24_sig &= ~RFCOMM_V24_DV;
>   
>   	rfcomm_dlc_set_modem_status(dlc, v24_sig);
>   


Kind regards,

Paul


[1]: 
https://web.git.kernel.org/pub/scm/linux/kernel/git/history/history.git/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Bluetooth: rfcomm: fix modem control handling
  2025-10-29 20:15 ` Paul Menzel
@ 2025-10-30 13:27   ` Johan Hovold
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2025-10-30 13:27 UTC (permalink / raw)
  To: Paul Menzel
  Cc: Luiz Augusto von Dentz, Marcel Holtmann, Johan Hedberg,
	linux-bluetooth, linux-kernel, stable

On Wed, Oct 29, 2025 at 09:15:28PM +0100, Paul Menzel wrote:

> Am 23.10.25 um 14:05 schrieb Johan Hovold:
> > The RFCOMM driver confuses the local and remote modem control signals,
> > which specifically means that the reported DTR and RTS state will
> > instead reflect the remote end (i.e. DSR and CTS).
> > 
> > This issue dates back to the original driver (and a follow-on update)
> > merged in 2002, which resulted in a non-standard implementation of
> > TIOCMSET that allowed controlling also the TS07.10 IC and DV signals by
> > mapping them to the RI and DCD input flags, while TIOCMGET failed to
> > return the actual state of DTR and RTS.
> > 
> > Note that the bogus control of input signals in tiocmset() is just
> > dead code as those flags will have been masked out by the tty layer
> > since 2003.
> > 
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> 
> There is a linux-history git archive [1], if somebody wants dig further. 
> But not relevant for the tag used by the stable folks.

Yeah, that's tree I use.

> Is there any way to test your change, to read DTR and RTS state?

This can be tested using the TIOCMGET and TIOCMSET (or
TIOCMBIS/TIOCMBIC) ioctls. I use a custom c application, and I'm not
aware of any particular application you can you use for testing if
that's what you were after.

Johan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-30 13:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-23 12:05 [PATCH v2] Bluetooth: rfcomm: fix modem control handling Johan Hovold
2025-10-23 12:51 ` [v2] " bluez.test.bot
2025-10-23 21:40 ` [PATCH v2] " patchwork-bot+bluetooth
2025-10-29 20:15 ` Paul Menzel
2025-10-30 13:27   ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).