Repository: pwr-Solaar/Solaar

Issue:
[046d:c534] with mouse M185 & keyboard K270
[Bus 001 Device 003: ID **046d:c534** Logitech, Inc.]

Solaar doesn't recognize this receiver.

```
usb 1-3: New USB device found, idVendor=046d, idProduct=c534
usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-3: Product: USB Receiver
usb 1-3: Manufacturer: Logitech
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
Logitech USB Receiver as /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/0003:046D:C534.0001/input/input4
hid-generic 0003:046D:C534.0001: input,hidraw0: USB HID v1.11 Keyboard [Logitech USB Receiver] on usb-0000:00:14.0-3/input0
input: Logitech USB Receiver as /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.1/0003:046D:C534.0002/input/input5
hid-generic 0003:046D:C534.0002: input,hiddev0,hidraw1: USB HID v1.11 Mouse [Logitech USB Receiver] on usb-0000:00:14.0-3/input1
```



Discussion:
I had same problem, but I'm using an M150 + K220 kit.

I still have the same problem too.....

Well, i think this Solaar project is dead now...
Nothing has been done since months :-)

You could just type in a terminal

solaar-cli show -v

Since I've done that I found out that I need a new usb-receiver (not nano but unifying, cost 8$ as bulk)

I have same combo with very same receiver and another receiver that is unifying for sure:

```
$ lsusb -d 046d:
Bus 005 Device 013: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 005 Device 012: ID 046d:c534 Logitech, Inc. Unifying Receiver
```

@Lekensteyn , 

I added c534 as nano receiver in the  lib/logitech_receiver/base_usb.py but after it `solaar show` fails with an `AttributeError` exception "Receiver object does not have _devices"  property.

If you guide a little I can get some more information. I can code python and have good knowledge on linux, but I don't know much about hid subsystem.

Information gathered from this USB receiver:

Kernel Log:

```
$ dmesg
[11659.044743] usb 5-4: new full-speed USB device number 5 using ohci-pci
[11659.217304] usb 5-4: New USB device found, idVendor=046d, idProduct=c534
[11659.217316] usb 5-4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[11659.217323] usb 5-4: Product: USB Receiver
[11659.217329] usb 5-4: Manufacturer: Logitech
[11659.226259] input: Logitech USB Receiver as /devices/pci0000:00/0000:00:13.0/usb5/5-4/5-4:1.0/0003:046D:C534.000D/input/input27
[11659.281582] hid-generic 0003:046D:C534.000D: input,hidraw8: USB HID v1.11 Keyboard [Logitech USB Receiver] on usb-0000:00:13.0-4/input0
[11659.287700] input: Logitech USB Receiver as /devices/pci0000:00/0000:00:13.0/usb5/5-4/5-4:1.1/0003:046D:C534.000E/input/input28
[11659.341407] hid-generic 0003:046D:C534.000E: input,hiddev0,hidraw9: USB HID v1.11 Mouse [Logitech USB Receiver] on usb-0000:00:13.0-4/input1
```

The /dev/ files:

```
ls /dev/hidraw? -l
[...]
crw-rw----+ 1 root root   248, 8 Out 15 02:15 /dev/hidraw8
crw-rw----+ 1 root root   248, 9 Out 15 02:15 /dev/hidraw9
```

Solaar (master branch):

```
$ tools/scan-registers.sh FF /dev/hidraw9
# Old notification flags: 000000
>> (   0.022) [10 FF 8100 000900] '\x10\xff\x81\x00\x00\t\x00'
<< (   0.020) [10 FF 8102 000000] '\x10\xff\x81\x02\x00\x00\x00'
>> (   0.024) [10 FF 8102 000217] '\x10\xff\x81\x02\x00\x02\x17'
--
<< (   4.600) [10 FF 81D0 000000] '\x10\xff\x81\xd0\x00\x00\x00'
>> (   4.604) [10 FF 81D0 000000] '\x10\xff\x81\xd0\x00\x00\x00'
--
<< (   4.626) [10 FF 81D2 000000] '\x10\xff\x81\xd2\x00\x00\x00'
>> (   4.628) [10 FF 8F81 D20300] '\x10\xff\x8f\x81\xd2\x03\x00'
--
<< (   4.650) [10 FF 81D4 000000] '\x10\xff\x81\xd4\x00\x00\x00'
>> (   4.652) [10 FF 8F81 D40300] '\x10\xff\x8f\x81\xd4\x03\x00'
--
<< (   4.674) [10 FF 81D6 000000] '\x10\xff\x81\xd6\x00\x00\x00'
>> (   4.678) [10 FF 81D6 090000] '\x10\xff\x81\xd6\t\x00\x00'
--
<< (   4.876) [10 FF 81E6 000000] '\x10\xff\x81\xe6\x00\x00\x00'
>> (   4.878) [10 FF 81E6 000000] '\x10\xff\x81\xe6\x00\x00\x00'
--
<< (   5.012) [10 FF 81F1 000000] '\x10\xff\x81\xf1\x00\x00\x00'
>> (   5.016) [10 FF 8F81 F10300] '\x10\xff\x8f\x81\xf1\x03\x00'
<< (   2.256) [10 FF 83B5 000000] '\x10\xff\x83\xb5\x00\x00\x00'
>> (   2.259) [10 FF 8F83 B50300] '\x10\xff\x8f\x83\xb5\x03\x00'
--
<< (   2.660) [10 FF 83D5 000000] '\x10\xff\x83\xd5\x00\x00\x00'
>> (   2.663) [11 FF 83D5 00465B31CB2015011700000000000000] '\x11\xff\x83\xd5\x00F[1\xcb \x15\x01\x17\x00\x00\x00\x00\x00\x00\x00'
```

Same command over /dev/hidraw8  returns a "broken pipe" exception.

Modified Solaar as:

```
$ git diff lib/logitech_receiver/base_usb.py
diff --git a/lib/logitech_receiver/base_usb.py b/lib/logitech_receiver/base_usb.py
index 7280579..69f0e50 100644
--- a/lib/logitech_receiver/base_usb.py
+++ b/lib/logitech_receiver/base_usb.py
@@ -48,6 +48,7 @@ NANO_RECEIVER_C521        = _nano_receiver(0xc521)
 NANO_RECEIVER_C525        = _nano_receiver(0xc525)
 NANO_RECEIVER_C526        = _nano_receiver(0xc526)
 NANO_RECEIVER_C52e        = _nano_receiver(0xc52e)
+NANO_RECEIVER_C534        = _nano_receiver(0xc534)


 del _unifying_receiver, _nano_receiver
@@ -65,4 +66,5 @@ ALL = (
                NANO_RECEIVER_C525,
                NANO_RECEIVER_C526,
                NANO_RECEIVER_C52e,
+               NANO_RECEIVER_C534,
        )
```

Then run it:

```
$ bin/solaar -D /dev/hidraw9 show
Exception AttributeError: "'Receiver' object has no attribute '_devices'" in <object repr() failed> ignored
solaar: error: Logitech receiver not found
```

System:

```
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial
Linux Wolf 4.4.0-42-generic #62-Ubuntu SMP Fri Oct 7 23:11:45 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
```

Now I need to understand what Solaar is looking for and why it is not getting it. I will try figure this out when I come back from my business trip. 

There is a duplicate issue #294 I opened before find this one. Could someone mark it as duplicate?

Regards,
Benito.

Hey @jrbenito, thanks for your investigation. Your changes to Solaar should be sufficient. Can you run `solaar show` with `--debug` and look for hints? The attribute `_devices` should really exist (see `lib/logitech_receiver/receiver.py`, class `Receiver`).

@Lekensteyn ,

Yes, I will do it and update this issue. However this will take until next week, due to bis trip I have no access to the receiver on this machine.

BRs
Jrbenito

Relates to #222 and #152 (different combo with same unrecognized receiver C534)

Tried the same approach @jrbenito presented (adding C534 to base_usb.py), got different error.

My device is at `hidraw1`:

```
$ ls /dev/hidraw? -l
crw------- 1 root root 245, 0 Out 25 15:24 /dev/hidraw0
crw------- 1 root root 245, 1 Out 25 15:24 /dev/hidraw1
crw------- 1 root root 245, 2 Out 25 14:15 /dev/hidraw2
crw------- 1 root root 245, 3 Out 25 14:15 /dev/hidraw3
```

```
$ bin/solaar -D /dev/hidraw1 show
solaar: error: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range(128)
```

@miguelpeixe ,

Did you got this using `root` user or regular user? Because you permission does not allow regular users to open the device node on `/dev`.

Also, did  you perform the test using `master` branch on this repo?

Thanks and regards

@Lekensteyn  and others,

here is the debug:

```
$ ./bin/solaar -dd show
11:33:25,962    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 83B5 030000]
11:33:25,964    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8F83 B50300]
11:33:25,964    DEBUG [MainThread] logitech_receiver.base: (3) device 0xFF error on request {83B5}: 3 = invalid value
11:33:25,965    ERROR [MainThread] logitech_receiver.receiver: open DeviceInfo(path=u'/dev/hidraw3', vendor_id=u'046d', product_id=u'c534', serial=u'\nMODALIAS=hid:b0003g0001v0000046Dp0000C534', release='2900', manufacturer='Logitech', product='USB Receiver', interface=1, driver=u'hid-generic')
Traceback (most recent call last):
  File "/home/jbenito/projetos/projs-python/Solaar/lib/logitech_receiver/receiver.py", line 525, in open
    return Receiver(handle, device_info)
  File "/home/jbenito/projetos/projs-python/Solaar/lib/logitech_receiver/receiver.py", line 340, in __init__
    assert serial_reply
AssertionError
Exception AttributeError: "'Receiver' object has no attribute '_devices'" in <object repr() failed> ignored
11:33:25,965    DEBUG [MainThread] solaar.cli: [/dev/hidraw3] => None
solaar: error: Logitech receiver not found
```

Seems related to registers I guess, am I right? Keep looking.

Good news!

Based on debug information I could figure out that reading serial number from device is failing (return none due to error). Solaar figures the maximum supported devices through the serial number, so also max_devices properties need to have a value. I cheated by hard coding serial number to zero and max_devices to 2 (this receive supports only two interfaces):

```
diff --git a/lib/logitech_receiver/receiver.py b/lib/logitech_receiver/receiver.py
index 1a01ba3..aff1ce9 100644
--- a/lib/logitech_receiver/receiver.py
+++ b/lib/logitech_receiver/receiver.py
@@ -336,10 +336,14 @@ class Receiver(object):

                # read the serial immediately, so we can find out max_devices
                # this will tell us if it's a Unifying or Nano receiver
-               serial_reply = self.read_register(_R.receiver_info, 0x03)
-               assert serial_reply
-               self.serial = _strhex(serial_reply[1:5])
-               self.max_devices = ord(serial_reply[6:7])
+                if self.product_id != 'c534':
+                    serial_reply = self.read_register(_R.receiver_info, 0x03)
+                    assert serial_reply
+                   self.serial = _strhex(serial_reply[1:5])
+                   self.max_devices = ord(serial_reply[6:7])
+                else:
+                    self.max_devices = 2
+                    self.serial = 0

```

Solaar now reports:

```
$ bin/solaar show
Unifying Receiver
  Device path  : /dev/hidraw3
  USB id       : 046d:c534
  Serial       : 0
    Firmware   : 29.00.B0015
  Has 2 paired device(s) out of a maximum of 2.
  Notifications: (none)

  1:
     Codename     :
     Kind         : keyboard
     Wireless PID : 4023
     Protocol     : unknown (device is offline)
     Polling rate : 20 ms (50Hz)
     Serial number: 00000000
     Battery: unknown (device is offline).

  2: Wireless Mouse
     Codename     :
     Kind         : mouse
     Wireless PID : 4038
     Protocol     : HID++ 2.0
     Polling rate : 8 ms (125Hz)
     Serial number: 00000000
          Firmware: RQM 54.00.B0004
     Supports 22 HID++ 2.0 features:
         0: ROOT                   {0000}
         1: FEATURE SET            {0001}
         2: DEVICE FW VERSION      {0003}
         3: DEVICE NAME            {0005}
         4: BATTERY STATUS         {1000}
         5: unknown:1830           {1830}   internal, hidden
         6: unknown:1850           {1850}   internal, hidden
         7: unknown:1860           {1860}   internal, hidden
         8: unknown:1890           {1890}   internal, hidden
         9: unknown:18A0           {18A0}   internal, hidden
        10: unknown:18C0           {18C0}   internal, hidden
        11: WIRELESS DEVICE STATUS {1D4B}
        12: unknown:1DF3           {1DF3}   internal, hidden
        13: REPROG CONTROLS        {1B00}
        14: unknown:1DF0           {1DF0}   hidden
        15: unknown:1E00           {1E00}   hidden
        16: unknown:1E80           {1E80}   internal, hidden
        17: unknown:1E90           {1E90}   internal, hidden
        18: unknown:1F03           {1F03}   internal, hidden
        19: VERTICAL SCROLLING     {2100}
        20: MOUSE POINTER          {2200}
        21: unknown:18B0           {18B0}   internal, hidden
     Has 3 reprogrammable keys:
         0: LEFT CLICK                 => LeftClick                     mse, reprogrammable
         1: RIGHT CLICK                => RightClick                    mse, reprogrammable
         2: MIDDLE BUTTON              => MiddleMouseButton             mse, reprogrammable
     Battery: 70%, discharging.

```

**Next Steps:**
- Figure out how to differentiate this receiver from the other nano receiver since serial number is not available ( @Lekensteyn any ideas based on your knowledge for this device? see #152 where you did extensive debug of it)
- Figure out if it is possible to retrieve device name somehow
- Yet this presents information on the prompt, it does not show on GUI, maybe due lack of device name?
- Prepare a pull request

The maximum number of devices is apparently not reliable, see for example #292. I have not seen the situation where the serial number can also not be retrieved, I guess showing zeroes for the serial and printing a warning is better than crashing. Not exactly sure how to handle the maximum though, do we know for sure that the maximum is always 2 for this receiver?

The device name should be retrievable via the Device Name feature (0x0005). This should already be implemented, see `lib/logitech_receiver/hidpp20.py:405`. Its specification is in https://lekensteyn.nl/files/logitech/logitech_hidpp_2.0_specification_draft_2012-06-04.pdf

@Lekensteyn .

No, we do not know for sure it only supports 2 devices but it is an educated guess based on the fact that, Logitech setpoint software does recognize those 2 devices, all combos at Logitech site are composed by 2 devices and, Logitech unifying windows software does not recognize this receiver (what, IMHO means I cannot pair/unpair devices to it. However, this is still just a guess.

The serial number reading is returning a error as command unknown,  and the try catch is translating this to none. I also agree that fallback to zero filed serial number and a warning is better than crash. But we will have to handle max devices too because it is derived from serial number.

I was reading the hid++ 2.0 spec on your site, will investigate deep to find why it is not being retrieved.

@Lekensteyn ,

I withdraw my guess above. Logitech provides a "re-connect software" for the nano receivers and indeed this software allow me to pair new devices. Now it reports 1 keyboard and 1 mouse connect (the combo itself). But **I dumped the information it provides and found the receiver also supports 6 devices**. The software also did not show any serial number for receiver nor for mouse and keyboard, maybe this is not supported here. 

Based on the **bold** above, I believe worth to setup a USB spy + windows virtual machine to dump USB communication from this software to the Nano receiver, we might find how does it figures the maximum allowed devices.

Out of curiosity, Logitech software reports firmware version '029.000.00015' and Solaar reports '029.000.B0015'. Where does that B comes from? Yet to discover. Same for the mouse, logitech´´s '054.000.00004' while Solaar 'RQM 054.000.B0004'.

Software reference: [Logitech support site for MK270](http://support.logitech.com/en_us/product/wireless-combo-mk270)

```
Re-Connect Software Version : 2.00.3
Dj Api Version : 2, 20, 7

Receiver
Name : wireless receiver
ModelId : 0x46dc534
Serial Number : 
Handle : 0xff000004
Wireless Status : 0x3
Firmware version : 029.000.00015
Bootloader version : 
Dfu Status : 0x1
Is Dfu Cancellable : Yes
Max Device Capacity : 6
```

Full dump on next message.

```
Bootloader version : 
Dfu Status : 0x1
Is Dfu Cancellable : Yes
Max Device Capacity : 6

    Mouse
    Name : 
    ModelId : 0x0
    Serial Number : 4038-00-00-00-00
    Handle : 0x2000006
    Wireless Status : 0x0
    Firmware version : 054.000.00004
    Bootloader version : 
    Dfu Status : 0x1
    Is Dfu Cancellable : No
    Battery Status : 0x3
    Parent Handle : 0xff000004

    Keyboard
    Name :  
    ModelId : 0x0
    Serial Number : 4023-00-00-00-00
    Handle : 0x1000005
    Wireless Status : 0x1
    Firmware version : 000.000.00000
    Bootloader version : 
    Dfu Status : 0x0
    Is Dfu Cancellable : No
    Battery Status : 0x0
    Parent Handle : 0xff000004


[16:40:52:0806]: ----------[09-13-2016]------------------------- Unifying API ------------------------------------

[16:40:52:0806]: <9824>Unifying Loaded DLL: 2.50.25

[16:41:21:0573]: -------------------------------------------------------------------------------------------------

[01:24:35:0042]: ----------[10-17-2016]------------------------- Unifying API ------------------------------------

[01:24:35:0042]: <8740>Unifying Loaded DLL: 2.50.25

[01:24:49:0335]: <6644>New Pairing successful: Device [K270 - 4003-3D-75-04-FA]

[01:25:10:0713]: -------------------------------------------------------------------------------------------------

[15:43:24:0311]: ----------[10-17-2016]------------------------- Unifying API ------------------------------------

[15:43:24:0317]: <8764>Unifying Loaded DLL: 2.50.25

[15:44:09:0542]: -------------------------------------------------------------------------------------------------

[11:12:41:0506]: ----------[11-09-2016]------------------------- Unifying API ------------------------------------

[11:12:41:0506]: <10680>Unifying Loaded DLL: 2.50.25

[11:12:42:0236]: <9440>HID++ contention false positive error detected (Idx:0xFF. Threshold:1.0 ms).

[11:12:46:0595]: <12516>Failed to read activity counter. Polling thread aborted.

[11:13:18:0250]: <10396>Failed to read activity counter. Polling thread aborted.

[11:13:51:0815]: <8400>Failed to read activity counter. Polling thread aborted.

[15:49:48:0560]: ----------[11-09-2016]------------------------- Unifying API ------------------------------------

[15:49:48:0571]: <12628>Unifying Loaded DLL: 2.20.7

[15:50:05:0568]: <10424>HID++ contention false positive error detected (Idx:0xFF. Threshold:1.0 ms).

[15:50:11:0688]: <13084>Failed to read activity counter. Polling thread aborted.

Log content displays the 100% of the available one.
```

Would be nice if you can create a pcap of the USB traffic :)

Either capture it using using something like USBPcap on Windows or use a VM as described at https://lekensteyn.nl/logitech-unifying.html

I am wondering if this device shouldn´t be bind by 'logitech-djreceiver' driver instead of 'hid_generic`... even the re-connection software has some`DJ API`and`Unifying DLL`. 


Resolving patch:
diff --git a/lib/logitech_receiver/descriptors.py b/lib/logitech_receiver/descriptors.py
--- a/lib/logitech_receiver/descriptors.py
+++ b/lib/logitech_receiver/descriptors.py
@@ -144,6 +144,11 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
 
 _D('Wireless Keyboard K230', protocol=2.0, wpid='400D')
 _D('Wireless Keyboard K270(unifying)', protocol=2.0, wpid='4003')
+_D('Wireless Keyboard MK270', protocol=2.0, wpid='4023',
+			        settings=[
+							_FS.fn_swap()
+						],
+				)
 _D('Wireless Keyboard K270', protocol=1.0,
 				registers=(_R.battery_status, ),
 				)
@@ -225,6 +230,7 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
 							_FS.lowres_smooth_scroll(),
 							_FS.pointer_speed(),
 				])
+_D('Wireless Mouse M185', protocol=2.0, wpid='4038')
 _D('Wireless Mouse M187', protocol=2.0, wpid='4019')
 _D('Wireless Mouse M215', protocol=1.0, wpid='1020')
 _D('Wireless Mouse M235')


Test patch: