pvvx / ATC_MiThermometer

Custom firmware for the Xiaomi Thermometers and Telink Flasher
https://github.com/pvvx/pvvx.github.io/tree/master/ATC_MiThermometer
Other
2.94k stars 205 forks source link

about encrypted beacon #78

Closed 50494554524F closed 3 years ago

50494554524F commented 3 years ago

can you tell me how should it work?! where do i set the key?!

it not clear on the flasher page...

thanks

pvvx commented 3 years ago

image

After flashing ATC1441 does not work. The ATC1441 firmware removes all keys and markings. Works after original firmware.

pvvx commented 3 years ago

Version 2.8: Added saving bindkey to EEP if mi-keys are erased

50494554524F commented 3 years ago

i had atc1441 before your firmware, thanks... now i have another problem...

updated to 2.8, ok. set a pincode, ok. tried to connect to the flasher, it asks the pincode, connected, ok.

after this first connection it doesn't connect anymore, remains stuck on "connect to: ....." ...

edit: rebooting the pc or removing the battery didn't resolve...

pvvx commented 3 years ago

Check the battery. Re-flashing strongly drains the battery.

50494554524F commented 3 years ago

i spent a bit of time trying... this is the way to reproduce the problem

i have other LYWSD03MMC but not here, so will test on other devices asap...

pvvx commented 3 years ago

Windows 10 supports only one bind device.

If you want to bind a new device with a pin code, then you need to remove the old device from the list. Android has no such problems. PS: Each binding of the device consumes a large enough battery power.

50494554524F commented 3 years ago

sorry, i don't understand... i'm using only one thermometer at the moment... the thermometer remains in use by windows after chrome stops using it, right?! ok, this isn't a problem, can be managed onece in a while... i'm just adding the pincode to prevent people near me can "hijack" the thermometer...

now, i have to figure out how the bindkey works because home assistant/ble_monitor says always unavailable when i turn on the ecncryption...

pvvx commented 3 years ago

Windows 10 and BLE bind + pin-code:

The first connection and entering the pin code. The device appears in the BT list: image The following connections will be successful as long as no other BLE devices with pin-code and binding are connected.

We take out the USB-BT adapter and change it to another one. Everything - the bind device becomes inaccessible! Entering a pin-code will not help: image Only removing from the BT list and a new bind and entering a pin code will help!

Likewise, if you already have another binding device in the BT list. Windows 10 will not connect and will ask for a pin code endlessly, ending with an error message.

Contact to Microsoft :)

50494554524F commented 3 years ago

oh ok, so no... i'm using only this thermometer at the moment... after the first successful connection, windows or chrome don't ask for the pincode or connect anymore... btw not a big problem.

pvvx commented 3 years ago

sorry, i don't understand... i'm using only one thermometer at the moment... the thermometer remains in use by windows after chrome stops using it, right?! ok, this isn't a problem, can be managed onece in a while...

Windows 10 will sometimes connected with a thermometer to show the battery level.

i'm just adding the pincode to prevent people near me can "hijack" the thermometer...

Windows needs to have this only device in the BT list for Chrome to connect. Then Chrome will connect.

now, i have to figure out how the bindkey works because home assistant/ble_monitor says always unavailable when i turn on the ecncryption...

Packages can be viewed by sniffer. The encoding of the encrypted packet is of the mijia standard.. An example of decoding.

pvvx commented 3 years ago

oh ok, so no... i'm using only this thermometer at the moment... after the first successful connection, windows or chrome don't ask for the pincode or connect anymore... btw not a big problem.

BLE pairing in Windows 10 is stored in the driver and adapter. Windows 10 only supports one pairing on common BT adapters. 👎

50494554524F commented 3 years ago

omg the battery, it's clear now...

about the bindkey: started from scratch with original firmware and reinstalled the 2.8... now it's working, i don't know why... ok

thanks for your patience

50494554524F commented 3 years ago

sorry to disturb you again... yesterday i was able to set and use the bindkey starting from scratch after few tests, i think the encryption doesn't work... i'm using MI format and encrypted beacon... here it is the steps to reproduce the problem

thanks

pvvx commented 3 years ago

If you have not erased mi keys, then Mi bindkey has priority.

50494554524F commented 3 years ago

more confusing now :D... i was supposed to use the bindkey returned by "do activation", right?!

50494554524F commented 3 years ago

erased mi bindkeys, read eep bindkey and used it... not working erased mi bindkeys, set my eep bindkey and used it... not working

at this point, mi format and encryption beacon don't work or i really don't understand how to use them together...

pvvx commented 3 years ago

erased mi bindkeys, set new bindkey и check: image

Use a sniffer to rule out any third-party software bugs.

50494554524F commented 3 years ago

i did exactly this... btw homeassistant/ble_monitor works with original firmware and bindkey, i'll ask them to check too

pvvx commented 3 years ago

Used mi bindkeys и check: image

pvvx commented 3 years ago

i did exactly this... btw homeassistant/ble_monitor works with original firmware and bindkey, i'll ask them to check too

After removing Mi keys and if something goes wrong, it is advisable to restart the device.

Reboot command: '721234':

image

The device will reboot after closing the connection. The command does the same as when removing and installing the battery.


Xiaomi 3 gateway (ZNDMWG03LM) accepts this coding. Mi-home Gateway with clouds works with the current firmware, If properly restored bindkey, name, ... in addition to the bindkey, the gateway is needed correct 4 byte counter (Mi CFG). Algorithm encoding taken from published examples of the mijia. Does not have differences from the original firmware.

50494554524F commented 3 years ago

someone told me how to enable debug for ble_monitor... i get a tons of "invalid data" rows, these rows disappear when i disable the encryption... so there's a bug somewhere in ble_monitor/firmware/homeassistant, my knowledge finish here and have to put this problem back in the line...

pvvx commented 3 years ago

Ver 2.9 - Added additional id flags to advertising packages Perhaps this will help if your program does not parse BLE Advertising Packages into blocks.

[0x02,0x01,0x06] is inserted at the beginning of the packet:

https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/

Data Type Value Data Type Name Reference for Definition
0x01 «Flags» Bluetooth Core Specification:Vol. 3, Part C, section 8.1.3 (v2.1 + EDR, 3.0 + HS and 4.0)Vol. 3, Part C, sections 11.1.3 and 18.1 (v4.0)Core Specification Supplement, Part A, section 1.3