Repository: pwr-Solaar/Solaar

Issue:
Instead of keyboard name it showing wireless pid
**Information**
<!-- Do not bother opening an issue for version 0.9.2 or older, it is extremely outdated. Please update to the latest one and see if your issue persists. -->
- Solaar: 1.0.1 latest git from PPA repo
- Distribution: Linux Mint 19.3
- Kernel version (ex. `uname -srmo`): `Linux 5.5.9-050509-lowlatency x86_64 GNU/Linux`
- Output of `solaar show`:
```
Nano Receiver
  Device path  : /dev/hidraw3
  USB id       : 046d:c517
  Serial       : None
solaar: error: 'NoneType' object is not iterable

```

**Describe the bug**
I noticed in a new Solaar version that I have now listed 11 years old [Logitech S 510 Cordless Keyboard](https://support.logi.com/hc/en-us/articles/360023308154-S-510-Technical-Specifications).
Only it has battery status and instead of keyboard name it showing wireless pid.
Like in screenshots:
![Solaar](https://user-images.githubusercontent.com/1978777/76764745-a852ad00-6795-11ea-80d6-6b8a2bb2884c.png)


Discussion:
That looks like a couple of bugs.  
The first one has to do with firmware for the receiver, I think.  Can you provide the output of `solaar probe`?   (I'm assuming you only have one receiver.)
The second has to do with the device with PID 8522.  What do old versions of solaar produce for it?
If possible, can you comment out the two lines in lib/solaar/cli/show.py that print the firmware
```
	for f in receiver.firmware:
		print ('    %-11s: %s' % (f.kind, f.version))
```
and try `solaar show` again?
Thanks.

Right - of course probe has the same problem.  Silly me.
Can you comment out the two lines in lib/solaar/cli/show.py
Also, select the receiver in the main window and click on the button with the letter i.
Old Solaar dosen't support this keyboard.

When I uncomment  this two line in show.py result is:
```
linux@mint:~$ solaar show
Nano Receiver
  Device path  : /dev/hidraw3
  USB id       : 046d:c517
  Serial       : None
  Has 2 paired device(s) out of a maximum of 1.
  Notifications: wireless (0x000100)
```
```
linux@mint:~$ solaar probe
Nano Receiver
  Device path  : /dev/hidraw3
  USB id       : 046d:c517
  Serial       : None
  Has 2 paired device(s) out of a maximum of 1.
  Notifications: wireless (0x000100)
  Register Dump
    Notification Register 0x00: 0x000100
    Connection State      0x02: 0x000200
    Device Activity       0xb3: None
    Pairing Register 0xb5 0x00: None
    Pairing Register 0xb5 0x10: None
    Pairing Register 0xb5 0x20: None
    Pairing Register 0xb5 0x30: None
    Pairing Name     0xb5 0x40: None
    Pairing Register 0xb5 0x01: None
    Pairing Register 0xb5 0x11: None
    Pairing Register 0xb5 0x21: None
    Pairing Register 0xb5 0x31: None
    Pairing Name     0xb5 0x41: None
    Pairing Register 0xb5 0x02: None
    Pairing Register 0xb5 0x12: None
    Pairing Register 0xb5 0x22: None
    Pairing Register 0xb5 0x32: None
    Pairing Name     0xb5 0x42: None
    Pairing Register 0xb5 0x03: None
    Pairing Register 0xb5 0x13: None
    Pairing Register 0xb5 0x23: None
    Pairing Register 0xb5 0x33: None
    Pairing Name     0xb5 0x43: None
    Pairing Register 0xb5 0x04: None
    Pairing Register 0xb5 0x14: None
    Pairing Register 0xb5 0x24: None
    Pairing Register 0xb5 0x34: None
    Pairing Name     0xb5 0x44: None
    Pairing Register 0xb5 0x05: None
    Pairing Register 0xb5 0x15: None
    Pairing Register 0xb5 0x25: None
    Pairing Register 0xb5 0x35: None
    Pairing Name     0xb5 0x45: None
    Firmware         0xf1 0x00: None
    Firmware         0xf1 0x01: None
    Firmware         0xf1 0x02: None
    Firmware         0xf1 0x03: None
    Firmware         0xf1 0x04: None
```
On further thought, I think that Solaar is behaving as it should for your keyboard.  As far as I can tell, Solaar never had any information about this keyboard - at least I can't find it in release 0.9.2 or 1.0.1 or any commit that mentions the keyboard.
To do better for your keyboard there needs to be a description of it in lib/logitech_receiver/descriptors.py.  But getting the right description requires knowing what the keyboard can do.  My guess is that 
```
_D('Wireless Keyboard K510', protocol=1.0, wpid='8522',
				registers=(_R.battery_status, ),
				settings=[
							_RS.fn_swap(),
						],
				)
```
Would be close to correct, but I'm assuming that this keyboard has the function-swap register.  The way to check would be to add this entry to descriptors.py and see whether changing Fn Swap does indeed change the behaviour of the function keys.
Old Solaar dosen't support this keyboard.
I think that the reason that is showing now is a recent new rework of logitech driver in kernel.
Yes, this receiver has no firmware information, which is tickling a very old bug.  I'll get that fixed momentarily.

Given that the receiver has no information in the pairing registers, I'm wondering how anything is showing up in the main window.
I also see that the receiver doesn't look at all like the current receivers, and the mouse has a connect button, which is not how other mice pair with the receiver.
So I don't expect that solaar can do much with your setup.
I'll fix the bugs, but even adding the keyboard information might not be a good idea.
I will need to connect this mouse, i use it last time before 7 years
This is [USB/PS2 cable reciver ](https://secure.logitech.com/assets/43283/s510-receiver-top-bottom.jpg) 
As i remember in older issue report contain more info about this reciver.  
There is more keyboard that use this reciver
The problem is that this receiver doesn't use the same information for paired devices that other receivers do, so Solaar might not be able to do anything with it.  You can try, for example `solaar pair` to pair a mouse, but be prepared for lots of things to not work.
Do you remember which issue involves the C517?
I searching through closed issues.
I found this same or similar reciver:
https://github.com/pwr-Solaar/Solaar/issues/234
I tried this command:
```
linux@mint:~$ solaar -dd show
16:21:06,863    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 83B5 030000]
16:21:06,872    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8F83 B50100]
16:21:06,872    DEBUG [MainThread] logitech_receiver.base: (3) device 0xFF error on request {83B5}: 1 = invalid SubID/command
16:21:06,872    DEBUG [MainThread] solaar.cli: [/dev/hidraw3] => <NanoReceiver(/dev/hidraw3,3)>
16:21:06,916    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 8102 000000]
16:21:06,920    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8102 000200]
Nano Receiver
  Device path  : /dev/hidraw3
  USB id       : 046d:c517
  Serial       : None
  Has 2 paired device(s) out of a maximum of 1.
16:21:06,920    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 8102 000000]
16:21:06,928    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8102 000200]
16:21:06,928    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 8100 000000]
16:21:06,936    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8100 000100]
  Notifications: wireless (0x000100)
16:21:06,936    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 83B3 000000]
16:21:06,944    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8F83 B30100]
16:21:06,944    DEBUG [MainThread] logitech_receiver.base: (3) device 0xFF error on request {83B3}: 1 = invalid SubID/command
16:21:06,944    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 8102 000000]
16:21:06,952    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8102 000200]
16:21:06,952    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 83B5 200000]
16:21:06,960    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8F83 B50100]
16:21:06,960    DEBUG [MainThread] logitech_receiver.base: (3) device 0xFF error on request {83B5}: 1 = invalid SubID/command
16:21:06,960    DEBUG [MainThread] logitech_receiver.base: (3) <= w[10 FF 83B5 040000]
16:21:06,968    DEBUG [MainThread] logitech_receiver.base: (3) => r[10 FF 8F83 B50100]
16:21:06,968    DEBUG [MainThread] logitech_receiver.base: (3) device 0xFF error on request {83B5}: 1 = invalid SubID/command
16:21:06,968    ERROR [MainThread] logitech_receiver.receiver: failed to read Nano wpid for device 1 of <NanoReceiver(/dev/hidraw3,3)>
16:21:06,968    ERROR [MainThread] logitech_receiver.receiver: register_new_device
Traceback (most recent call last):
  File "/usr/share/solaar/lib/logitech_receiver/receiver.py", line 422, in register_new_device
    dev = PairedDevice(self, number, notification)
  File "/usr/share/solaar/lib/logitech_receiver/receiver.py", line 104, in __init__
    raise _base.NoSuchDevice(number=number, receiver=receiver, error="read Nano wpid")
logitech_receiver.base.NoSuchDevice: {'number': 1, 'receiver': <NanoReceiver(/dev/hidraw3,3)>, 'error': 'read Nano wpid'}
16:21:06,969  WARNING [MainThread] logitech_receiver.receiver: <NanoReceiver(/dev/hidraw3,3)>: looked for device 1, not found
```
Issue #109 is probably closer.
The exception and warning are as expected.  This receiver does not support the registers that Solaar (at least solaar show) accesses to look for paired devices.

You might want to try `solaar -dd`.  This might show why the main window gives some information about your keyboard.
Now i connected old Logitech  LX5 Cordless Optical Mouse, and only mouse is showed in device list without keyboard.
And also missing device name:
 Mouse Wireless PID:  3622
I expect that something is going wrong, but that the GUI works a bit differently from `solaar show` so it can provide some information.   Submitting the output of `solaar -dd` might make it possible to do a bit better.
solaar -dd:
[logitech-debug.txt](https://github.com/pwr-Solaar/Solaar/files/4339127/logitech-debug.txt)

I see a couple of things in that log:
1/ A device is signalling, but its device number is too high.  This should be fixed in my recent patch, so some more information may become available.
2/ There is another place where there is an assumption that firmware is always available.  I'm putting in a PR to fix this problem.  Once this PR is merged in things might improve.
But it is still the case that this receiver is quite different from the receivers that Solaar is built to handle so there may be further problems that are not fixable.
solaar -dd:
[logitech-debugg-2.txt](https://github.com/pwr-Solaar/Solaar/files/4343450/logitech-debugg-2.txt)


Hmm.  I didn't see the difference that I was expecting.  
Could you try to change the maximum number of pairings for your receiver by changing line 58 to
```
	'max_devices': 6,
```
in lib/logitech_receiver/base_usb.py.  It should currently have a 2 in the line.   Also make sure that the C517 receiver line reads
```
NANO_RECEIVER_C517        = _nano_receiver_max2(0xc517)
```
Then provide output of `solaar -dd` and a screen shot of the main window if it is different from the screen shot you already provided.
Now is showing keyboard and mouse in GUI.
![Solaar-3](https://user-images.githubusercontent.com/1978777/76914236-f19c1d00-68b9-11ea-8d3c-2f75c1fbbb3c.png)

solaar -dd:
[logitech-debugg-3.txt](https://github.com/pwr-Solaar/Solaar/files/4346398/logitech-debugg-3.txt)

OK.  I have a couple of changes that will help with the receiver.   It would be nice to have names for the keyboard and mouse.   The S510 is the name for the entire set.  Do you know what the keyboard and mouse are called?  This information is probably on the bottom of the keyboard and the mouse.

Resolving patch:
diff --git a/lib/logitech_receiver/base_usb.py b/lib/logitech_receiver/base_usb.py
--- a/lib/logitech_receiver/base_usb.py
+++ b/lib/logitech_receiver/base_usb.py
@@ -60,6 +60,17 @@
 	're_pairs': True 
 }
 
+_nano_receiver_maxn = lambda product_id, max: {
+	'vendor_id':0x046d,
+	'product_id':product_id,
+	'usb_interface':1,
+	'hid_driver':_DRIVER,
+	'name':'Nano Receiver',
+	'max_devices': max,
+	'may_unpair': False,
+	're_pairs': True 
+}
+
 _lenovo_receiver = lambda product_id: {
 	'vendor_id':0x17ef, 
 	'product_id':product_id, 
@@ -84,7 +95,7 @@
 NANO_RECEIVER_ADVANCED    = _nano_receiver(0xc52f)
 
 # Nano receivers that don't support the Unifying protocol
-NANO_RECEIVER_C517        = _nano_receiver_max2(0xc517)
+NANO_RECEIVER_C517        = _nano_receiver_maxn(0xc517,6)
 NANO_RECEIVER_C518        = _nano_receiver(0xc518)
 NANO_RECEIVER_C51A        = _nano_receiver(0xc51a)
 NANO_RECEIVER_C51B        = _nano_receiver(0xc51b)
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
@@ -152,6 +152,10 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
 _D('Wireless Keyboard K270', protocol=1.0,
 				registers=(_R.battery_status, ),
 				)
+_D('Wireless Keyboard MK300', protocol=1.0, wpid='8521',
+				registers=(_R.battery_status, ),
+				)
+
 _D('Wireless Keyboard MK320', protocol=1.0, wpid='200F',
 				registers=(_R.battery_status, ),
 				)
@@ -225,8 +229,11 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
 							_FS.new_fn_swap()
 						],
 				)
-_D('Craft Advanced Keyboard', protocol=4.5, wpid='4066')
+_D('Craft Advanced Keyboard', codename='Craft', protocol=4.5, wpid='4066')
 
+_D('Wireless Keyboard S510', codename='S510', protocol=1.0, wpid='3622',
+				registers=(_R.battery_status, ),
+				)
 
 # Mice
 
@@ -362,6 +369,12 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
 							_RS.side_scroll(),
 						],
 				)
+_D('LX5 Cordless Mouse', codename='LX5', protocol=1.0, wpid='5612',
+				registers=(_R.battery_status, ),
+				)
+_D('Wireless Mouse M30', codename='M30', protocol=1.0, wpid='6822',
+				registers=(_R.battery_status, ),
+				)
 
 # Trackballs
 


Test patch: