Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have a question. #2

Open
dbdbdee opened this issue Jan 8, 2024 · 5 comments
Open

I have a question. #2

dbdbdee opened this issue Jan 8, 2024 · 5 comments

Comments

@dbdbdee
Copy link

dbdbdee commented Jan 8, 2024

First of all, I am not good at English. Please understand.

I start pairing on Unifying software and when I connect the device, it works well until the device presses the key.

But when I disconnect and reconnect the device, it doesn't work.

Every time I reconnect the device, I have to make a new pairing to make the device work.

I want the device to work without pairing when I reconnect the device if it's already paired.

What should I do?

@decrazyo
Copy link
Owner

decrazyo commented Jan 8, 2024

A device gets a unique RF address and AES encryption key when it's paired to a receiver.
My example code will forget those values when it's powered off.

To fix this, you would have to save the RF address and AES encryption key to non-volatile memory, such as flash or EEPROM, after pairing and load those values back into memory when the device is rebooted.
The way you do that depends on what hardware you're using, which is why I didn't include that functionality in the example code.

I have added comments to the example code to indicate what needs to be done.

I would recommend looking at the Arduino EEPROM library to learn about saving and loading data.
https://docs.arduino.cc/learn/built-in-libraries/eeprom

@dbdbdee
Copy link
Author

dbdbdee commented Jan 9, 2024

Thank you for your answer.

if(err) {
uint8_t id = random();
uint16_t product_id = 0x1025;
uint16_t device_type = 0x0147;
uint32_t crypto = random();
uint32_t serial = 0xA58094B6;
uint16_t capabilities = 0x1E40;
char name[] = "Hacked";
uint8_t name_length = strlen(name);

err = unifying_pair(&state,
id,
product_id,
device_type,
crypto,
serial,
capabilities,
name,
name_length);
}

printf("Address : %d %d %d %d %d\n",address[0],address[1],address[2],address[3],address[4]);
printf("AesKey : %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n",aes_key[0],aes_key[1],aes_key[2],aes_key[3],aes_key[4],aes_key[5],aes_key[6],aes_key[7],aes_key[8],aes_key[9],aes_key[10],aes_key[11],aes_key[12],aes_key[13],aes_key[14],aes_key[15]);

for(int i = 0; i < 5; i++) {
EEPROM.write(i, address[i]);
}
for(int i =0; i <16; i++) {
EEPROM.write(i+5, aes_key[i]);
}

I modified the code like this at the bottom.

uint32_t aes_counter = random();
// TODO: Check if we have previously paired to a receiver.
// If so, load "address" and "aes_key" from non-volatile memory.
for(int i = 0; i < 5; i++) {
address[i]=EEPROM.read(i);
}
for(int i = 0; i <= 16; i++) {
aes_key[i]=EEPROM.read(i+5);
}
printf("Address : %d %d %d %d %d\n",address[0],address[1],address[2],address[3],address[4]);
printf("AesKey : %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n",aes_key[0],aes_key[1],aes_key[2],aes_key[3],aes_key[4],aes_key[5],aes_key[6],aes_key[7],aes_key[8],aes_key[9],aes_key[10],aes_key[11],aes_key[12],aes_key[13],aes_key[14],aes_key[15]);

I modified the code at the top like this.

But after the initial pairing was successful, it doesn't work when I remove and reconnect the device.

@bilabar
Copy link

bilabar commented Nov 19, 2024

Hi @decrazyo. Is there any working example for that?
I also have same problem as above.
Do RF address is address variable or from *state.address?

@decrazyo
Copy link
Owner

I've done some limited testing and gotten mixed results.

I updated the example sketch to save and load the RF address and AES key from the EEPROM.
Once the Arduino has paired to a Unifying receiver, I can hit the reset switch on the Arduino and it will reconnect to a receiver as expected.
If, instead, I unplug the Arduino and plug it back in then it can't manage to reconnect to the receiver.

I'm assuming that unplugging/plugging in the Arduino takes long enough that the receiver notices the lack of keep-alive packets and considers the device to actually be disconnected, while resetting the Arduino happens fast enough that the receiver don't notice the disconnect.

If that's the case then my best guess is that I haven't accurately replicated the way that Unifying devices reconnect to a receiver.

@anistor
Copy link

anistor commented Dec 25, 2024

Thanks for adding pairing persistence. I'll try it out soon. Two strange things I noticed so far with the older version is : 1. After pairing , moving the mouse works but sending encrypted keystrokes does not work and 2. Using the connection utility to put the dongle în pairing mode works, pairing seems to happen as mouse movements start working immeditelly, but the connection utility still shows the dongle as unpaired. This second fact makes me wonder if pairing was really completed by both parties and key properly derived. I'm guessing the lack of proper key would explain non-working keystrokes. Maybe this is also somwhow related to why even after adding persistence of pairing data you are still not able to re-pair. Does the connection utility show your dongle as paired ? Thanks! Happy holidays!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants