Pairing Logitech Unifying Devices on GNU/Linux

A few weeks ago I bought new mouse and keyboard. Having limited USBs available, I preferred Logitech’s new ‘Unifying’ ones. This unifying feature enables you to use more than one devices by pairing them with a single receiver.

After unboxing my new gear, I navigated to Logitech’s web page to get information about unifying procedure. Logitech provides a small utility for pairing unifying devices, nice. However, in the list of available operating systems there is no GNU/Linux. It would be nice if Logitech provided required utility for Linux as well, however, being a part of GNU/Linux community is nicer, eh?

An awesome guy named Benjamin Tissoires written a small C program (licensed with GPL predictably) that enables pairing Logitech unifying devices with receiver and shared it on linux.kernel mailing list*. Isn’t it great?

Here is the code:

Since WordPress messes with the code, I uploaded it as raw file. Click here to download it.

Assuming you have saved the file with name unifying_pair.c, you can build using command

$ gcc -o unifying_pair unifying_pair.c

One more thing you need to know before pairing is the location of your device under /dev/. In my case it was /dev/hidraw2 (actually i couldn’t manage to find the difference between hidraw0, hidraw1 and hidraw2 but i just tried them all).

Then become root (or use sudo, doesn’t matter),

# ./unifying_pair /dev/hidraw2

and turn your device on when the application tell you to do so, and you’re done.

That’s all folks! Smile

72 thoughts on “Pairing Logitech Unifying Devices on GNU/Linux

  1. Chooch

    Thanks for the work on this. Unfortunately it won’t compile for me. Tons of errors about #include requiring a filename after it and undeclared variables (errno, EINVAL, etc.)

    Do I need to set something up in my environment, perhaps? Sorry if it’s a stupid question, but I’ve done very little programming.

    I’m using Kubuntu 12.04 if that helps at all.

    Reply
    1. Chooch

      Oops – nevermind.. I clicked through to the kernel mailing list and saw that what was posted there was just missing a bunch of text on my screen. Might be my browser doing something goofy on your page Smile

      Ignore me.. moving along..

      Reply
      1. th0th Post author

        Actually you are right, looks like I made a mistake while copying the source. Now I fixed and it should work.

        Reply
  2. GC

    Error: 32
    write: broken pipe.

    ^^ I get the above error on all 3 hidraw devices .

    No fun for me Frown

    Reply
    1. Anton

      Unfortunately, I get the broken pipe as well on all three /dev/hidraw[0-2] on Ubuntu 10.04 (yeah, I know it’s EOL).

      Reply
  3. hernan

    It worked for me, thank you! One observation though: I was trying to add a mouse and in the first try the program would run but the mouse pointer wouldn’t move so I ran it again with no luck. Only after unplugging and replugging the receiver I got both devices to work, a keyboard and a mouse.

    Reply
  4. Dan Kaervang

    Works like a charm.
    I had to guess which hidraw device to use, but once I got the right on it worked just like that.
    Thanks for posting about this, and thumbs up to Benjamin Tissoires for a job well done.

    Reply
  5. Gregory

    Thanks so much to the Benjamin Tissoires and to this post’s author. I actually lost my K400′s receiver (I have no idea how), but remember my dad had a logitech mouse he wasn’t using anymore.

    If anyone is wondering, they sell these receivers alone on ebay pretty cheap if you need one.

    Reply
  6. Jack

    I’m also getting the broken pipe. However, when I switch out the unifying receiver for a non-unifying one, I get the right messages. Not sure, though if I have the right HID driver. I suspect this unify.c only works on a certain driver level and above. I’m running a nearly stock Debian squeeze on my production Desktop. Will try it on a more modern release on my Testing boot later. Perhaps my experimenting can help someone else.

    Reply
  7. Larry

    At the top of the code are a couple lines:

    #define USB_DEVICE_ID_UNIFYING_RECEIVER (__s16)0xc52b

    It so happens that this is the device ID that you can find by using

    # lsusb
    Bus 003 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
    (what I see on my system)

    I would assume that if your receiver has a different ID, you could adjust the #define to match it and then compile and run.

    Just a guess. I’m not a coder.

    Reply
  8. Mikez

    @gc -
    There are 4 /dev/hidraw devices -
    Try all four of them -
    One will report “not a unifying receiver”
    Two will report “broken pipe”
    The other one will “just work”.

    Reply
  9. ikhsan

    Have any of you tried this on 32-bit machine? Some of the reader on my blog reported that it spits out a warning during the compile process. It compile just fine btw.

    To eliminate the error message, i replaced the following line

    printf(“write: %d were written instead of %ld.n”, res,

    with

    printf(“write: %d were written instead of %zu.n”, res,

    and the warning went away

    Reply
  10. Tim van Dalen

    I only have one /dev/hidraw (0), which reports that it is ready to pair a new device and that I should switch my device on to do so.
    I can’t get it to detect my device though, even when the yellow light on my M705 is on, the program still reports that is is ready.

    I’m on x86_64 arch linux, does anybody else have this problem?

    Reply
  11. Pingback: Thinkpad W520安装Ubuntu 12.04折腾记 - 很宅.com

  12. Anthony Hook

    Worked like a charm with /dev/hidraw1 (my old mouse) pairing with my new receiver for the keyboard (/dev/hidraw3) apparently. (System: Ubuntu 12.10 x64) Thanks a bunches.

    Also, compiles with g++ as well.

    Reply
  13. TheSpaceApache

    Amazing! After a horrible day at work, I was considering smashing my skull in when my new logitech k360 wouldn’t work alongside my m325 mouse. Fortunately my better(?) judgement persuaded me to hunt down this article instead.

    Thank you. All is well…at the bottom of a bottle of Jameson’s…

    Reply
  14. egar g.

    This works under Lubuntu 11.10 (Oneiric Ocelot). Prima.
    Compiling does not work with Lubuntu 12.10 quantal Quetzal.
    Terminal message:
    unifying_pair.c: In function ‘main’:
    unifying_pair: 78:25: warning: format ‘% ld’ expects argument of type ‘long int’, but argument 3 has type ‘unsigned int’ [-Wformat]

    What is wrong?

    Reply
  15. Thomas Tanghus

    Again thanks for the post. Pairing worked really well, but am I the only one who experiences that sometimes the mouse or the keyboard doesn’t respond on input? There’s nothing relevant in dmesg or syslog.

    Reply
  16. Brigitte

    I get an “Error 32: Broken Pipe” on all three hidraw’s. 32 bit system, Ubuntu 10.04. Not very good with these things, not sure what to try…

    Reply
  17. anonymous coward

    Thanks a lot to you and Benjamin. Paired keyboard and mouse on /dev/hidraw0 Smile
    Btw, HTML garbled the C source, had to copy it from this page’s source view and replace the named entities with real ampersands.

    Reply
  18. Nicci

    Thanks for this post, it worked well for me on Ubuntu 12.10. I did have to click through to the kernel list to get the full code including comments, but once I did that it worked like a charm.

    Reply
  19. Rion Redinger

    Thanks a MILLION!!! I was beginning to think I had been ripped off with a bad mouse and receiver. I’m a happy camper now!

    Reply
  20. Pingback: Emparejar dispositivos Logitech Unifying en Linux « Informático de Guardia

  21. Andrew Dennis

    I know I’m a bit late to the party, but thought I’d add in my “works perfectly, first time, every time” two cents here… Downloaded, compiled, executed the file, and turned the keyboard off and on once, and shazamm… everything is paired (trackball & keyboard) with less effort than I would have believed.

    Reply
  22. Wade

    I’m using Ubuntu 12.10. I can see my receiver using lsusb, but I have nothing resembling hidraw in /dev/.
    I’m using the M515 Mouse, K360 Keyboard.

    Reply
  23. Dan Bowkley

    The code compiles fine for me, but when I plug the receiver in I get no additional devices listed in /dev. Anyone got any ideas where to start?

    syslog snippet:

    Mar 3 11:29:40 karla-K55A kernel: [66919.258514] usb 3-2: new full-speed USB device number 19 using xhci_hcd
    Mar 3 11:29:40 karla-K55A kernel: [66919.277009] usb 3-2: New USB device found, idVendor=046d, idProduct=c52b
    Mar 3 11:29:40 karla-K55A kernel: [66919.277014] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    Mar 3 11:29:40 karla-K55A kernel: [66919.277017] usb 3-2: Product: USB Receiver
    Mar 3 11:29:40 karla-K55A kernel: [66919.277019] usb 3-2: Manufacturer: Logitech
    Mar 3 11:29:40 karla-K55A mtp-probe: checking bus 3, device 19: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-2"
    Mar 3 11:29:40 karla-K55A kernel: [66919.282073] logitech-djreceiver 0003:046D:C52B.001F: hiddev0,hidraw0: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-2/input2
    Mar 3 11:29:40 karla-K55A kernel: [66919.282346] logitech-djreceiver 0003:046D:C52B.001F: logi_dj_probe:logi_dj_recv_query_paired_devices error:-32
    Mar 3 11:29:40 karla-K55A mtp-probe: bus: 3, device: 19 was not an MTP device
    Mar 3 11:29:40 karla-K55A kernel: [66919.282527] logitech-djreceiver: probe of 0003:046D:C52B.001F failed with error -32
    Mar 3 11:34:28 karla-K55A kernel: [67206.897002] usb 3-2: USB disconnect, device number 19
    Mar 3 11:34:40 karla-K55A kernel: [67219.170894] usb 3-3: new full-speed USB device number 20 using xhci_hcd
    Mar 3 11:34:40 karla-K55A kernel: [67219.189231] usb 3-3: New USB device found, idVendor=046d, idProduct=c52b
    Mar 3 11:34:40 karla-K55A kernel: [67219.189235] usb 3-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    Mar 3 11:34:40 karla-K55A kernel: [67219.189238] usb 3-3: Product: USB Receiver
    Mar 3 11:34:40 karla-K55A kernel: [67219.189240] usb 3-3: Manufacturer: Logitech
    Mar 3 11:34:40 karla-K55A mtp-probe: checking bus 3, device 20: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-3"
    Mar 3 11:34:40 karla-K55A mtp-probe: bus: 3, device: 20 was not an MTP device
    Mar 3 11:34:40 karla-K55A kernel: [67219.194160] logitech-djreceiver 0003:046D:C52B.0022: hiddev0,hidraw0: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-3/input2
    Mar 3 11:34:40 karla-K55A kernel: [67219.194431] logitech-djreceiver 0003:046D:C52B.0022: logi_dj_probe:logi_dj_recv_query_paired_devices error:-32
    Mar 3 11:34:40 karla-K55A kernel: [67219.194549] logitech-djreceiver: probe of 0003:046D:C52B.0022 failed with error -32

    Reply
  24. miko

    By the way, is there somebody knowing on which technology and protocol is based the “unifying ready” thing ?

    It looks like it shares the same radio band than WiFi and Bluetooth : is there more connexion to theses protocols and technology ?

    Dominique

    Reply
  25. Innocent Bystander

    Please buy this man a beer. Thank you very much for the trick. Works perfect.
    Xubuntu 12.10, Logitech combo MK520, Acer Aspire One 722, on dev/hidraw0

    Reply
  26. Arjen Lentz

    I appear to have the same problem as Dan Bowkley above..

    [ 3116.975884] usb 3-2: new full-speed USB device number 6 using xhci_hcd
    [ 3116.994772] usb 3-2: New USB device found, idVendor=046d, idProduct=c52b
    [ 3116.994780] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    [ 3116.994783] usb 3-2: Product: USB Receiver
    [ 3116.994786] usb 3-2: Manufacturer: Logitech
    [ 3117.000682] logitech-djreceiver 0003:046D:C52B.000C: hiddev0,hidraw0: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-2/input2
    [ 3117.000967] logitech-djreceiver 0003:046D:C52B.000C: logi_dj_probe:logi_dj_recv_query_paired_devices error:-32
    [ 3117.001223] logitech-djreceiver: probe of 0003:046D:C52B.000C failed with error -32

    But, I had it working *once*, when switching to another USB port. Perhaps there’s a timing problem in the logitech-djreceiver driver?

    Reply
  27. Jonno

    Noob here on Ubuntu 12.04 64 bit. Having troubles with my M570 mouse and don’t really get how to compile and download this file… Any instructions available? Thanks in advance!

    Reply
  28. salem

    Thanks! spent ages copying winxp VMs over to my new machine with the thought to use one of them to pair my new HTPC keyboard (logitech k700). but then I thought I should google for a native ubuntu way, and it worked! so easy.
    ubuntu 12.10 64 bit.

    Reply
  29. Ivo Jimenez

    Do you know if it’s technically possible to pair one device to multiple receivers? It seems that an encryption key is exchanged from the receiver to the device so that it only talks to that receiver and not to any other. I wonder if that can be shared to another receiver so that i. My personal workflow doesn’t involve any scenario where both receivers are active (either one or the other)

    Reply
    1. th0th Post author

      I don’t think it is possible to use one device with multiple receivers. I am just assuming though. May be you can plug two different receivers to two different computers, run pairing tool on both computers at the same time and then turn off and on the device while both receivers are waiting for the signal. If you ever have a chance, please share the result with me Smile

      Reply
  30. Glenn

    Just installed mint and was really bored with trackpad. Found a unifying usb tried this and works like a charm. Kudos to you!

    Reply
  31. Justinas

    Prior to buying keyboard (K520) together with Mouse (M310) and unifying wifi USB I had other mouse – M705.
    Which in its description didn’t say anything about unifying wifi USB.
    But, as I tried, I still could unify keyboard to my old mouse wifi USB.

    Excelent, now I have spare mouse with wifi USB.

    Reply
  32. Ro$k0

    Great job and big thanks to Benjamin Tissoires!!! I were able to unify my new K360 keyboard(typing on it) and old M515 mouse on Ubuntu 13.04 x32.

    Reply
  33. Alex

    This works perfectly for me as well, using SUSE 12.3.

    However, one issue I’m having is that every time I shut down the computer and reboot, it doesn’t work anymore. I’m plug my wired mouse and keyboard up, perform the command again, and repeat.

    I’m sure it’s something obvious, but I’m a rookie here. Any help would be greatly appreciated!

    Reply
  34. Thomas

    It worked! Not sure why but I had to use “sudo ./unifying_pair /dev/hidraw0″ instead of the suggested.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>