Re: Possible bug in the cp210x kernel driver?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Malte,

The mailings lists reject html so can you see if you can disable that
in you mail client when replying?

On Mon, Sep 20, 2021 at 05:51:43PM +0200, Malte Bayer wrote:

> > In event mode the device is supposed to replace any '0xec' characters
> > in the input stream with the string '0xec 0x00', which the driver then
> > needs to convert back to '0xec'.
> > 
> > But clearly your device doesn't escape '0xec' as expected.
> > 
> > What type of cp210x are you using?
> 
> Its the Silabs CP2102 DCL00X1612+

I used a CP2102 when implementing support for the embedded-event mode
and just verified that everything is working as expected.

The batch number "DCL00X" might provide some insight here though.
Searching for it gives a few hits describing counterfeit CP2102 devices
which has that particular number. [1][2] Apparently they behave
mostly like the real ones, but I wouldn't be surprised if they did not
implement the event mode.

It seems people were able to use the difference in responses to
malformed requests to determine which chips were fake. The below patch
is first stab at it based on [3].

Supposedly, the fake ones would only return a single byte in response,
while the CP2102 I have hear happily returns the full eight byte
requested.

Can apply the patch and send me the logs from when connecting your
device?

This might require some experimentation (e.g. different request,
length), but if we're lucky the malformed type request is all that's
needed to determine when event mode is supported.

Johan

[1] https://hackaday.com/2017/08/14/hands-on-with-the-shacamp-2017-badge/
[2] https://mobile.twitter.com/sha2017badge/status/1167902087289532418
[3] https://github.com/SHA2017-badge/cp2102-det/blob/master/main.c


>From 43cab5bee8b12617d97998fa956553aef62fa704 Mon Sep 17 00:00:00 2001
From: Johan Hovold <johan@xxxxxxxxxx>
Date: Tue, 21 Sep 2021 10:24:47 +0200
Subject: [PATCH] dbg: USB: serial: cp210x: add cp2102 quirk instrumentation

Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
 drivers/usb/serial/cp210x.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 66a6ac50a4cd..51d99d29dde1 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -2074,6 +2074,20 @@ static void cp210x_init_max_speed(struct usb_serial *serial)
 	priv->use_actual_rate = use_actual_rate;
 }
 
+static void cp2102_determine_quirks(struct usb_serial *serial)
+{
+	u8 data[8];
+	int ret;
+
+	ret = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST,
+			CP210X_GET_PARTNUM, data, sizeof(data));
+	if (ret)
+		return;
+
+	dev_info(&serial->interface->dev, "%s - %*ph\n", __func__,
+			(int)sizeof(data), data);
+}
+
 static int cp210x_get_fw_version(struct usb_serial *serial, u16 value)
 {
 	struct cp210x_serial_private *priv = usb_get_serial_data(serial);
@@ -2108,7 +2122,13 @@ static void cp210x_determine_type(struct usb_serial *serial)
 		return;
 	}
 
+	dev_info(&serial->interface->dev, "%s - type = 0x%02x\n", __func__,
+			priv->partnum);
+
 	switch (priv->partnum) {
+	case CP210X_PARTNUM_CP2102:
+		cp2102_determine_quirks(serial);
+		break;
 	case CP210X_PARTNUM_CP2105:
 	case CP210X_PARTNUM_CP2108:
 		cp210x_get_fw_version(serial, CP210X_GET_FW_VER);
-- 
2.32.0




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux