zmkfirmware / zmk

ZMK Firmware Repository
https://zmk.dev/
MIT License
2.71k stars 2.76k forks source link

Bluetooth security failing on windows machine #805

Open aureumleonis opened 3 years ago

aureumleonis commented 3 years ago

I've been using a split/nice!nano handwired built for a few months already with no issues on my personal PC. On the other hand, The keyboard pairs correctly with the my work laptop but doesn't send any keypresses. Both of these are windows 10 machines. I finally took the initiative to enable debugging and saw this happen constantly (a couple of times per second)

[00:25:58.514,068] <err> zmk: Security failed: <redacted> (public) level 1 err 2
[00:25:58.639,770] <dbg> zmk.split_central_disconnected: Disconnected: <redacted> (public) (reason 19)
[00:25:58.639,831] <dbg> zmk.disconnected: Disconnected from <redacted> (public) (reason 0x13)
[00:25:58.639,862] <dbg> zmk.update_advertising: advertising from 2 to 2
[00:25:58.678,680] <dbg> zmk.split_central_connected: Connected: <redacted> (public)
[00:25:58.678,680] <dbg> zmk.split_central_process_connection: Current security for connection: 1
[00:25:58.679,901] <dbg> zmk.split_central_process_connection: New connection params: Interval: 48, Latency: 0, PHY: 1
[00:25:58.679,992] <dbg> zmk.connected: Connected thread: 0x20002e40
[00:25:58.679,992] <dbg> zmk.connected: Connected <redacted> (public)
[00:25:58.680,023] <dbg> zmk.update_advertising: advertising from 0 to 2

I may have the beginning/end of the log wrong but this is still the part that repeats. Does anybody know what the problem could be? Is there anything else I can I do to find more data about the problem?

haywirephoenix commented 3 years ago

Have you tried switching the bluetooth profile for your work machine? It's right here in the docs https://zmkfirmware.dev/docs/behaviors/bluetooth/#bluetooth-pairing-and-profiles

aureumleonis commented 3 years ago

I've tried these two scenarios

Personal + work PCs

Only work PC

haywirephoenix commented 3 years ago

Maybe related: I've noticed an issue when using BT_CLR you have to remove+repair the paired device from the list and restart the pc before it will register input.

It may be worth doing a full settings clear and trying again without touching BT_CLR https://zmkfirmware.dev/docs/troubleshooting/#split-keyboard-halves-unable-to-pair

aureumleonis commented 3 years ago

This is not a new problem BTW. I've dealt with it for around 5 months. I've done all the permutations of resets (BT_CLR and flashing), restarts and even tried a separate bluetooth dongle. No luck.

The other thing I've noticed though is some of the time the board will just not pair at all after clearing. I get the message "Couldn't connect. Try connecting again."

Kikokeyco commented 3 years ago

I'm having the same problem with my nrf52840 based custom board, it will connect, allow me to type a couple inputs, and then disconnects, on both my mac and my iphone.

aureumleonis commented 2 years ago

I'm having the same problem with my nrf52840 based custom board, it will connect, allow me to type a couple inputs, and then disconnects, on both my mac and my iphone.

I seem to have a different problem than yours. Windows displays the device as connected briefly but it never detects any input.

I just rebuilt and flashed firmware with latest ZMK hoping that maybe the zephyr 2.5 thing fixed the issue but it didn't. Is there something else I can do to further debug this problem? It's kind of a bummer that I have this wireless keyboard that I can't use wirelessly... I was considering building another one but I'm having doubts since it's likely going to have the same problem.

Edit: added reply to @Kikokeyco

aureumleonis commented 2 years ago

I just tested my board with BlueMicro and that firmware does connect to the work laptop successfully.

Avada-sao commented 2 years ago

I got the same problem.On Windows it can’t detect any input.But on my Ubuntu,and my IOS,it works.Also,I tested my keyboard with BlueMicro on my Windows,it works, too .

sadekbaroudi commented 1 year ago

Just to add to the list here, I have experienced the same thing. I have tested two different keyboards on 6 different devices.

Consistent behavior between Keyboard A and Keyboard B (both nice!nanos). All machines are Windows or Android OS:

Similar to comments above, I have tried clearing profiles, flashing the reset settings uf2, clearing and re-pairing. I even tried connecting after a full reformat and reinstallation of windows on the personal laptop 1. Consistent behavior.

caksoylar commented 1 year ago

@sadekbaroudi Are you sure your BT adapters support BLE? It needs to support BT version 4.2 for the security ZMK uses, if I remember correctly.

sadekbaroudi commented 1 year ago

@caksoylar I went and checked bluetooth versions on all my laptops / desktop. Interestingly, the ones that work are Bluetooth 5.0, and the ones that don't are Bluetooth 5.2

caksoylar commented 1 year ago

I see, following this my adapter (AX200-based PCIe) reports LMP 11.9210 which indicates 5.2 also; it worked on both Windows 10 and 11. Maybe it is some other factor.

sadekbaroudi commented 1 year ago

Thanks for confirming that!

claviger-pc commented 1 year ago

I also have had alot of trouble with a BT60. I have done every possible combination of clearing profiles, using reset firmware, etc, and have also done usb logging, tried different zmk versions, etc. For me it is also several months and I am wondering if it isn't the AX200, perhaps there was a problematic driver update. I installed the latest driver from Intel and that didn't help.

whitehatmiddleman commented 1 year ago

I think this might be a zmk firmware issue with BT5.2 or greater. I have another nicenano with kmk (ble enabled) and I can connect, remove, clear and re-pair for the same host. Where as with ZMK, I'm unable to repair entirely.

As for other systems with BT5.0, zmk works accordingly.

whitehatmiddleman commented 1 year ago

I think this might be a zmk firmware issue with BT5.2 or greater. I have another nicenano with kmk (ble enabled) and I can connect, remove, clear and re-pair for the same host. Where as with ZMK, I'm unable to repair entirely.

As for other systems with BT5.0, zmk works accordingly.

It seems that Pete's branch [zephyr/3.1](git clone --branch zephyr/3.1-upgrade https://github.com/petejohanson/zmk.git) might be a good fix. I have a corne (simple, no oled or rgb) with nice_nanos and so far I'm able to clear the profile and remove the device from windows and re-pair the keyboard. One thing to note is that once you remove the device from windows you need to restart the host, then you can re-pair the keyboard.

I'm assuming zephyr 3.1[3.2 based on app/west.yml] seems to improve bluetooth connectivity with hosts.

caksoylar commented 1 year ago

For reference, #1499 is the associated PR for the Zephyr upgrade.

whitehatmiddleman commented 1 year ago

For reference, #1499 is the associated PR for the Zephyr upgrade.

Awesome, looking forward to the merge. If I run into any issues with the PR branch, I report them accordingly.

sadekbaroudi commented 1 year ago

Oooh, yay! Looking forward to trying that out as well!

vanessa-luna commented 1 year ago

I also really hope this gets resolved. My new Corne with niceNano are not staying reliably connected to my Win10 machine. I increased the bluetooth power, and removed all profiles and started over to no avail. IT will work temporarily then stop until I remove and re-pair.

My laptop has a Intel® Wi-Fi 6E AX210 No vPro®... My laptop reports LMP 12.14198

whitehatmiddleman commented 1 year ago

I also really hope this gets resolved. My new Corne with niceNano are not staying reliably connected to my Win10 machine. I increased the bluetooth power, and removed all profiles and started over to no avail. IT will work temporarily then stop until I remove and re-pair.

My laptop has a Intel® Wi-Fi 6E AX210 No vPro®... My laptop reports LMP 12.14198

If you don't have too much features with your corne keyboard, you can use the following repo and branch: https://github.com/petejohanson/zmk/tree/zephyr/3.1-upgrade

I've been running this for over a month and I don't experience any connectivity issues.

vanessa-luna commented 1 year ago

I hate to ask this kind of question here @greyhatmiddleman but I am out of practice. With this branch I will have to run and compile on my local machine, and I can follow the ZMK docs to get that going yes? (rather than use github actions) Also why if I don't have too many features? Is this branch lacking in features? Thank you for the info.

caksoylar commented 1 year ago

With this branch I will have to run and compile on my local machine, and I can follow the ZMK docs to get that going yes?

You can do that following ZMK development docs, or change which ZMK fork/branch your config repo points to to build using Github actions.

Also why if I don't have too many features? Is this branch lacking in features? Thank you for the info.

This branch is related to PR #1499, features like underglow/displays might have issues potentially, but I believe it is pretty much ready for final testing so you shouldn't expect many issues.

whitehatmiddleman commented 1 year ago

@vanessa-luna @caksoylar beat me to answer your questions. He is correct with his response.

zhenchaopro commented 1 year ago

It seems that both master and PR #1499 don't work with BT 5.2( Window 10 with LMP 11). My Macbook Pro works fine.

vanessa-luna commented 1 year ago

It seems that both master and PR #1499 don't work with BT 5.2( Window 10 with LMP 11). My Macbook Pro works fine.

The PR has worked for me in Win10 with LMP 12. Have you also ensured you remove ALL BT profiles on the keyboard before pairing after the firmware update? It will be discouraging if this doesn't fix it for everyone. When you say it doesn't work, does it fail in the same way others are describing above?

zhenchaopro commented 1 year ago

@vanessa-luna Yeah, I tried it for several times. and the Split battery reporting branch works at the first time, it fails to connect after restart. PR https://github.com/zmkfirmware/zmk/pull/1499 fails at the first time.

whitehatmiddleman commented 1 year ago

@vanessa-luna Yeah, I tried it for several times. and the Split battery reporting branch works at the first time, it fails to connect after restart. PR #1499 fails at the first time.

When I reflash my controllers, I normally would initially flash with a 'settings_reset' uf2 firmware to clear anything in the controllers before flashing any new firmware. Check Troubleshooting, although this is in reference to the halves not pairing, it ensures anything stuck in Flash is cleared.

Once you've created a 'settings_reset' uf2 firmware you can keep this for future resets, no need to constantly recompile a settings reset uf2.

MajykOyster commented 1 year ago

I'm seemingly having the same connection issues, using Zephyr 3.2.

On Windows 11 : device is detected, but most of the time I get the following error message : "try connecting your device again". When I don't get this error, connection is successful, but I can only type for a few seconds, then status switches randomly between "connected" and "paired". If I try to connect via bluetooth when USB is connected on the main side of my split keyboard only, the connection works. Both sides are functional, until I unplug the main side.

On Manjaro : Connection fails immediately, no specific message.

On Android : sometimes it works, but most of the time I get an error about incorrect PIN or security key.

I tried to reset the firmware and to clear bluetooth profiles, no cookie so far.

j-ea commented 1 year ago

It looks like PR #1499 was merged, but unfortunately the Windows BLE 5.1+ issue still persists.

My nice!nano board does not connect on Windows 10 w/ BLE 5.1. I get the error "Couldn't connect. Try connecting again."

It works when the connected via USB. It works on the same machine while booted into different flavors of Linux. It also works on a different Windows 10 device w/ BLE 4.2.

caksoylar commented 1 year ago

Dual booting will always have issues since hardware keys are shared across different OS: #549. This also sounds consistent with the error message you are getting.

j-ea commented 1 year ago

@caksoylar, thank you for the quick reply! I'll give this a try tonight and reply here.

j-ea commented 1 year ago

This was correct. Thanks again. Dual booting was causing the issues.

I'm dual booting with Linux and Windows. I see the PR was never merged. I'm happy to update it, add relevant Linux info, and submit another PR if anyone would find it useful.

caksoylar commented 1 year ago

That would be good but I think it would be better if we directly refer to an existing resource rather than maintaining this ourselves. Arch wiki BT page (section 2.1) is a good and well-maintained candidate, although it doesn't include information on the Windows-macOS pairing, naturally.

l3ztum commented 1 year ago

I'm having the same problem and i'm on Zephyr 3.2

My xiao ble board does not connect on Windows 10 Enterprise with integrated BLE 5.2. Settings show toggle between paired and connected.

What works:

What i tried:

sheedapistawl commented 1 year ago

I have the same problem, and Zephyr 3.4 test did not solve the issue either.

jacksonSingleton commented 1 year ago

Having this problem on Windows, I can pair to MacOS just fine. But Windows gives an error: "try connecting your device again" when using a cleared profile. I'm using nice!nanos, no dual boot, and am able to successfully pair other BT devices such as wireless game controllers to the same machine. Any solutions at all?

alternateved commented 1 year ago

I think I might be having the same issue with Aurora Corne on Fedora Linux with laptop with BT 5.3:

[00:09:24.707,855] <dbg> zmk: split_central_connected: SKIPPING FOR ROLE 1
[00:09:24.707,885] <dbg> zmk: connected: Connected thread: 0x20004dd0
[00:09:24.707,977] <dbg> zmk: connected: Connected 7C:B5:66:65:9D:97 (public)
[00:09:24.709,289] <dbg> zmk: update_advertising: advertising from 0 to 2
[00:09:24.768,157] <dbg> zmk: auth_pairing_accept: role 1, open? yes
[00:09:24.908,599] <err> zmk: Security failed: 7C:B5:66:65:9D:97 (public) level 1 err 9
[00:09:24.914,489] <dbg> zmk: split_central_disconnected: Disconnected: 7C:B5:66:65:9D:97 (public) (reason 42)
[00:09:24.914,581] <dbg> zmk: disconnected: Disconnected from 7C:B5:66:65:9D:97 (public) (reason 0x2a)
[00:09:24.914,611] <dbg> zmk: update_advertising: advertising from 2 to 2

I was able to pair and unpair with no issues with older laptop and with Android phone but for this laptop no combination of clearing Bluetooth profiles, resetting firmware, reflashing helped. Once I tried branch from https://github.com/zmkfirmware/zmk/pull/1853 I was finally able to connect and use the keyboard. First pairing with this laptop worked for a few days, then suddenly I was unable to reconnect.

gabeklavans commented 1 year ago

I believe I'm facing the same issue. Haven't got USB debugging yet but I'm seeing:

Using 2 nice!nanos in a crkbd split

I might try #1853 but it looks pretty WIP right now

NickPancakes commented 1 year ago

Another person who suddenly ran into this issue yesterday, presumably (I didn't capture any debug logs). I only connect via BT to a single Windows 11 PC, but I also often connect wired to a KVM that switches between the Win11 PC and and an M1 Macbook. Tried: Resetting BT profiles, rebuildling+reflashing zmk, un/reinstalling BT devices+drivers in Win11. However, the Zephyr 3.4 branch linked above (and modified with the diffs from the latest comments on the PR) appears to have fixed the issue for me, for now at least.

joelspadin commented 11 months ago

For anyone who started getting this in the last couple of months, check the version of your Bluetooth driver (Settings > Apps > Installed Apps > search for "bluetooth"). If you have Intel Wireless Bluetooth driver version 22.250.0, try uninstalling it and installing version 22.240.0 instead.

fulaphex commented 11 months ago

for the problems with pairing with Windows 11, I found https://github.com/zmkfirmware/zmk/pull/1853 to be quite helpful. As it stands, the PR is very much work-in-progress, as of writing this message I had to revert to https://github.com/zmkfirmware/zmk/pull/1853/commits/540c6f6e1b7281c9f1c36535667fec02fd3a5669 to even be able to compile zmk, but after building the firmware with the 3.4, windows manages to pair. I still cannot get the pairing to work consistently 100%, but once it's paired - it connects without any issues and that's all I care for right now

gabeklavans commented 11 months ago

For anyone who started getting this in the last couple of months, check the version of your Bluetooth driver (Settings > Apps > Installed Apps > search for "bluetooth"). If you have Intel Wireless Bluetooth driver version 22.250.0, try uninstalling it and installing version 22.240.0 instead.

I used the Roll Back Driver feature in my Win11 device manager, which put it back at 22.230.0.2. I can confirm with this driver, my ZMK corne works over bluetooth on my machine now.

Though I'm not sure how I feel on recommending that people downgrade crucial drivers as a fix... but it does work for now.

jmding8 commented 11 months ago

I just ran into this issue. I tried:

  1. clear all the profiles from both the board
  2. unpair from the PC
  3. restart the PC
  4. reset the board

What ultimately fixed it for me was doing a settings reset (https://zmk.dev/docs/troubleshooting#split-keyboard-halves-unable-to-pair).

TomzBench commented 10 months ago

For anyone who started getting this in the last couple of months, check the version of your Bluetooth driver (Settings > Apps > Installed Apps > search for "bluetooth"). If you have Intel Wireless Bluetooth driver version 22.250.0, try uninstalling it and installing version 22.240.0 instead.

I used the Roll Back Driver feature in my Win11 device manager, which put it back at 22.230.0.2. I can confirm with this driver, my ZMK corne works over bluetooth on my machine now.

Though I'm not sure how I feel on recommending that people downgrade crucial drivers as a fix... but it does work for now.

Can confirm this solution worked for me as well! (And I couldnt give a shit about the security of my windows shitbox. its a fine solution. Though I'm curious if this is something that needs to be patched on the keyboard side? or a bug in intel driver that can eventually be patched in a future update)

phuertay commented 10 months ago

Solved by following #1487. I'm using a custom split w/Nice!nanos on Windows 11 with the newest Intel driver (22.250.0.2)

  1. Add "CONFIG_BT_CTLR_PHY_2M=n" to the .conf file (in my case, zmk-config/config/dacman56.conf)
  2. Load settings_reset.uf2 on both sides
  3. Load firmware on both sides
  4. Re-paired
jakubgrygiel commented 9 months ago

For anyone who started getting this in the last couple of months, check the version of your Bluetooth driver (Settings > Apps > Installed Apps > search for "bluetooth"). If you have Intel Wireless Bluetooth driver version 22.250.0, try uninstalling it and installing version 22.240.0 instead.

I had the same issue (corne split, 2x nice nanos). I recently updated my Windows drivers and returning to an older bluetooth version solved the problem

gabeklavans commented 7 months ago

Looks like the latest release that includes Zephyr 3.5 fixes this issue. I've rebuilt my firmware using the docker container at the main tag, and I am having no issues connecting when my Intel Bluetooth driver is updated to 22.250.0.2

sharifrazzaque commented 6 months ago

Same here. My keyboard (running ZMK from July 2023) would not pair with my new Windows 11 laptop. I Rebuilt with 3.5 just now and it paired to the same win 11 laptop w/o any problems. I did not have to reset keyboard settings, roll back Bluetooth drivers or anything else besides update to ZMK 3.5

rayanpiro commented 6 months ago

Zephyr 3.5 Corne keyboard and NRF52840.

Same here. Using win11 and a BT 5.3 dongle. If I try to connect with my win10 laptop's intel card it works properly.

I've tried https://github.com/zmkfirmware/zmk/issues/805#issuecomment-1866956993 too and isn't working for me.