All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marius Zachmann <mail@mariuszachmann.de>
To: Aleksandr Mezin <mezin.alexander@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: corsair-cpro and hidraw
Date: Thu, 17 Jun 2021 08:27:25 +0200	[thread overview]
Message-ID: <2199169.9u6qy3EJ5v@marius> (raw)
In-Reply-To: <CADnvcf+LhxZoZk9eRUahSWZ3xVJLkxcAt3+4dS-JCjV8gZE_0A@mail.gmail.com>

Am Donnerstag, 17. Juni 2021, 05:11:10 CEST schrieben Sie:
> Hello.
> 
> I've noticed that corsair-cpro communicates with the device in
> request-reply pattern, and also exposes hidraw interface, so userspace
> can also send requests. How does the driver figure out that the
> current input report is a response to the request sent by the driver,
> and not for some other request from userspace? Also if userspace reads
> from hidraw, how can it be sure that the report it read is the
> response to its last request, and not to some driver's request?
> 
> I do not have the hardware, I was just looking at corsair-cpro as a
> reference - I'm working on a driver for a similar device (nzxt rgb &
> fan controller)
> 

Hello,
Sadly, it doesn't. There is no way to distinguish where the reply is
coming from. The hardware should probably use report ids in the first
byte of the reply for something like this, but it does not.
I thought about possibilities to stop hidraw before a request and
restart it after the reply, but there is (as far as I know) no way
to do this without changing the hid-driver. Maybe I should have a
look at this idea again.
The choice was either to allow it or block most userspace tools.
I also tried to get false readings and it can be done, albeit
highly unlikely.
As a "solution" I slapped a comment at the beginning of the driver
to point out the problem.

I do not know, what your device is doing, but the (similar) corsair-psu
driver has the same problem. This device uses an echo of the command
in the answer and if they don't match it returns an error. This could
maybe lead to a false error when the replies are switched, but is
probably preferable.

Greetings
Marius



  parent reply	other threads:[~2021-06-17  7:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17  3:11 corsair-cpro and hidraw Aleksandr Mezin
2021-06-17  4:33 ` Aleksandr Mezin
2021-06-17  6:27 ` Marius Zachmann [this message]
2021-06-17  7:11   ` Aleksandr Mezin
2021-06-17 13:14     ` Guenter Roeck
2021-06-17 23:56       ` Aleksandr Mezin
2021-06-18  5:45         ` Wilken Gottwalt
2021-06-18  6:18           ` Marius Zachmann
2021-06-18  6:47             ` Wilken Gottwalt
2021-06-18  7:06               ` Marius Zachmann
2021-06-18 12:13                 ` Guenter Roeck
2021-06-18 12:22                   ` Marius Zachmann
2021-06-18 19:41                     ` Guenter Roeck
2021-06-18 12:10               ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2199169.9u6qy3EJ5v@marius \
    --to=mail@mariuszachmann.de \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=mezin.alexander@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.