Commit Graph

1898 Commits

Author SHA1 Message Date
Benjamin Tissoires
3d380af3a8 prevent error to be shouted when the .probe() returns -ENODEV
Seen on the second input node of the Roccat Kone XTD:
"ratbag error: ROCCAT Kone XTD: driver specified in hwdb not found: roccat

With the new hwdb matching, we should not try any other driver not having
the right id, so simplify the for loop to find the driver only.

Fixes #32

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-12 17:26:37 -04:00
Peter Hutterer
46b7a15663 Start using the __attribute__((cleanup))
Not a lot of use-cases in the main libratbag code yet, but the protocol
handling and hidraw bits may make more use of it.
2015-10-13 07:01:49 +10:00
Peter Hutterer
5b8f3c4744 Add snprintf_safe() and sprintf_safe helpers
Blows up when sprintf encounters an error, the result string is empty or the
result string is truncated.

Note: sprintf_safe only works on static buffers, it uses ARRAY_LENGTH.

Fixes #14

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 07:01:09 +10:00
Peter Hutterer
1abc7cdb69 Add strdup_safe() as a reliable strdup function
Handles NULL and guarantees a successful strdup

Fixes #14

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-13 07:00:16 +10:00
Benjamin Tissoires
c464c86fa4 fix ratbag_button_get_special
looks like a cpy-paste-o

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-12 16:08:06 -04:00
Peter Hutterer
357191b1e0 Improve the README a bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-12 10:55:26 +10:00
Benjamin Tissoires
d9645c0e4b hidpp20: document the names of the features in gaming mice
This patch adds nothing but some debug outputs and prepares the code
to support the recent gaming mice from Logitech.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-11 10:28:37 -04:00
Benjamin Tissoires
4abdb634cf hidpp20: add a define to document feature 0x0003
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-11 10:25:16 -04:00
Benjamin Tissoires
f4777e7b71 hidpp20: fix adjustable DPI for older mice
The G502 uses the version 0 of the adjustable DPI feature. This version
does not echo the given parameters which raised a -EIO in libratbag.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-11 10:24:45 -04:00
Benjamin Tissoires
439e287776 fix readme for the doc
github is happy with the current README but doxygen is not.
Use the same formatting than the architecture.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-09 17:23:42 -04:00
Benjamin Tissoires
e606473198 update README
update README to reflect the hwdb change.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-09 17:19:16 -04:00
Benjamin Tissoires
9b18b877a7 hwdb: fix MX master entry
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-09 17:03:44 -04:00
Benjamin Tissoires
f48ee7e25b hwdb: fix udev rule for uhid devices
The MX Master is using BLE to connect, and so the system sees it as a uhid
device. The current rule ignores it because uhid devices do not have the
ID_BUS set.

Fix that by detecting uhid devices and put the bus in the hwdb accordingly.

For completeness, also add usb through uhid so we can also replay devices
and test their drivers.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-09 17:03:25 -04:00
Benjamin Tissoires
ebad4ecd0a test: fix the loading of the test driver
This test driver is already twisting a little bit the API, so twist it
a little bit more.

An other solution would be to just add a (void* data) parameter to .probe()
but there is no point in it because only test_driver would be used.

Create a new probe callback only used when using the test driver, so make
check is happy.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-09 16:26:39 -04:00
Thomas Hindoe Paaboel Andersen
3605bede48 Use udev rules/hwdb to match mice to drivers and SVGs
This adds udev rules/hwdb that sets RATBAG_DRIVER and RATBAG_SVG
properties to the event devices. We then use this property to select
the correct driver instead of checking the hardcoded list in the
drivers. Having this in a hwdb makes it easier for users to test
if drivers match their mouse with a system installed libratbag.

Each driver now has an "id" which is used to match the driver set
in RATBAG_DRIVER. A SVG can optionally be set as well.

All entries in the hwdb are currently without a name as that
information was not available in the hardcoded lists.

Note that this patch breaks the test-driver.
2015-10-09 21:05:33 +02:00
Benjamin Tissoires
5278d43429 hidraw: add 2 hidraw functions to fetch the usage page and the usage of a report
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-08 11:43:07 -04:00
Benjamin Tissoires
44dc1f7462 Revert "hidraw: ratbag_hidraw_has_report() can also match the usage and usage page"
This reverts commit d5a20efd8b.

The API is horrible. Better having 2 additional functions to get
the usage and usage pageof the report.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-08 08:27:43 -04:00
Benjamin Tissoires
48ce20ae21 hidraw: allow uhid devices to detect siblings
When using uhid devices, we might want to check for siblings too. This is
a corner case so that's why it might not work in 100% of the cases.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 20:14:10 -04:00
Benjamin Tissoires
d5a20efd8b hidraw: ratbag_hidraw_has_report() can also match the usage and usage page
Add a match against the usage page and the usage.
If we are not interested in this new match, we can just use 0.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 20:14:10 -04:00
Benjamin Tissoires
d95885c52c hidraw: fix endianness when parsing the report descriptor
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 20:14:10 -04:00
Benjamin Tissoires
a207fa0989 hidraw: store the report usage page and usage
We might need to check against them too, so parse them and store them.

It is a little bit tricky when there is no report ID. In this case, assume
that the Collection(Application) is a match.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 20:14:10 -04:00
Benjamin Tissoires
aacdb9923e hidraw: the report ID can be of arbitrary size
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 20:14:10 -04:00
Benjamin Tissoires
1175d69741 hidraw: store a struct when parsing the report descriptor
We will be interested in the type of reports, so prepare the storage
by using an external struct to store the reports.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 20:14:10 -04:00
Benjamin Tissoires
63a1202890 hidraw: remove duplicated code
ratbag_open_hidraw is a special case of ratbag_find_hidraw() when
we do not check for the parent and we do not have a match.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:46:24 -04:00
Benjamin Tissoires
13c3d9a110 hidraw: do not open twice the same hidraw node
When using the same context, we do not want to open twice the same
hidraw node if two input node match it.
Store the sysname in the ratbag_device so we can check if it has been
opened previously.

Note that ratbag-command list still shows all input node as working
because we just close them as soon as we opened them.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:46:19 -04:00
Benjamin Tissoires
1cbb80b7b4 keep track of opened devices
If we want to remove the duplicate nodes opened when using
ratbag_find_hidraw(), we need to somehow keep track of all opened
ratbag_device.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:46:15 -04:00
Benjamin Tissoires
e71ac0a088 hidpp20drv: add support of Logitech G502
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:22 -04:00
Benjamin Tissoires
975c91ae54 hidraw: allow opening of sibling devices
Some mice have a separate hid interface for configuring the advanced
features. It occurs that this is a common enough use case to be handled
directly by libratbag-hidraw instead of having a per-device quirk.

The idea is to allow opening the sibling hidraw devices during .probe()
and to give a matching callback. If the callback succeeds, then the
hidraw node will be used.
With this, one device might be opened several times, this has to be fixed
in a separate commit.

Fixes issue #19

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:21 -04:00
Benjamin Tissoires
ce37417525 hidraw: break ratbag_open_hidraw in two
We want to be able to find sibling hidraw nodes. For that, we need to
open and test several different hidraw nodes. Makes the opening of a
specific hidraw node in its own function.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:21 -04:00
Benjamin Tissoires
abde78e6c4 hidraw: check if the hidraw node corresponds to the ratbag device
We were retrieving the hidraw information but did not use them.
Now the debug output "foo is device 'bar'" is only shown when there is
a match.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:21 -04:00
Benjamin Tissoires
4538d03b36 hidraw: remove now useless storage of the udev hidraw node
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:21 -04:00
Benjamin Tissoires
00f8f90288 hidraw: make ratbag-hidraw responsible for all hidraw related operations
libratbag.c does not need to initialize anything hidraw related, so
move out everything to libratbag-hidraw.c.
That means that calling ratbag_close_hidraw() is not a requirement
whithin the drivers to exit properly.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:21 -04:00
Benjamin Tissoires
7dfa8cb75e hidraw: move ratbag_device_init_hidraw() in libratbag-hidraw
We are touching hidraw internals here, better having the function in
libratbag-hidraw.c.

No functional changes.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:21 -04:00
Benjamin Tissoires
936ad60da4 remove unused parameter in ratbag_device_init_hidraw()
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-10-07 18:30:21 -04:00
David Herrmann
958e86f67e ratbagctl: pick default device if none given for show-device
Lets use the new get_device_path() helper to allow calling show-device
without any argument. This follows what show-profile does already.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 19:02:12 +02:00
David Herrmann
acb0118897 ratbagctl: split get_profile_path()
Split get_profile_path() and provide an helper for get_device_path() on
its own.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 19:00:27 +02:00
David Herrmann
85a045c538 ratbagctl: move get_profile_path()
Move get_profile_path() up to make it available to other verbs as well.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 18:57:42 +02:00
David Herrmann
fbffe241e6 ratbagctl: add show-profile verb
New verb: show-profile

This simply prints a profile of a given device by querying ratbagd for
all information on the selected profile.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 18:56:25 +02:00
David Herrmann
765fd1565a ratbagd: expose resolutions on the bus
Add a new property to profiles that exposes resolutions on the bus. We
simply expose a dictionary entry for each resolution, hence, we can
easily extend it in the future. However, we avoid the full overhead of
real dbus objects, as there is no real need for it.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 18:55:03 +02:00
David Herrmann
1a677c0b1d ratbagd: add DBus methods to retrieve object paths
Add two new helpers to query ratbagd for the object-paths of a specific
object:
  GetDeviceByName: Return device given a device name
  GetProfileByIndex: Return a profile given a profile index

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 18:53:54 +02:00
David Herrmann
eeb8788413 ratbagctl: print the default profile
Include the default profile in 'show-device' output.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:35:00 +02:00
David Herrmann
c24ca68d63 ratbagd: expose 'DefaultProfile'
Add a new property that exposes the default profile.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:34:32 +02:00
David Herrmann
e189dc3b1f ratbagd: never return ENODATA for Get()
We should always provide valid data if requested via Get().
Unfortunately, DBus still does not include 'maybe' types, so we just
return something that is clearly invalid data.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:33:30 +02:00
David Herrmann
ff8f391e91 ratbagctl: implement list-devices and show-device
Two new verbs for ratbagctl:
 - list-devices: list all available devices
 - show-device: show detailed information about a single device

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:23:51 +02:00
David Herrmann
0a9c2824ba ratbagd: expose profile information
Expose a list of profiles, including a tag for the active profile, from
within each ratbagd device via DBus.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:23:51 +02:00
David Herrmann
dc37d3bf62 ratbagd: ignore NULL profiles
Never return information about non-existant profiles. Just skip NULL
profiles silently, when iterating.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:23:51 +02:00
David Herrmann
2780e6f3d7 ratbagd: simplify profile DBus paths
Refrain from hierarchical paths and instead use object prefixes with
unique paths each. This avoids several nasty DBus-enforced behaviors
regarding deep hierarchies. Furthermore, it keeps the names shorter,
which is always a nice side-effect.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:23:51 +02:00
David Herrmann
260df58856 ratbagd: profile profile accessors
Provide two new profile accessors that return the path and index of a
profile. This also requires us to cache the dbus path in the profile
itself.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:23:51 +02:00
David Herrmann
cba28a97a0 ratbagd: add ratbagd_device_get_name()
New helper to return the name of a device. This will be required to build
hierarchical paths in the sub-classes, like profiles.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 16:23:51 +02:00
David Herrmann
eca2203603 ratbagd: add manager interface
Instead of relying on the cricket ObjectManager interface, use our own
manager interface. This gets rid of ridiculous recursive behavior of the
ObjectManager interface and instead allows us to control the behavior.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2015-09-29 14:09:23 +02:00