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

esp_hid_host cannot connect to USB Keyboard: Authentication fail reason 5 (IDFGH-6368) #8027

Closed
ChrisIdema opened this issue Dec 7, 2021 · 8 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@ChrisIdema
Copy link

Environment

  • Development Kit: ESP32-Wrover-Kit
  • Kit version (for WroverKit/PicoKit/DevKitC): v1
  • Module or chip used: ESP32-WROOM-32
  • IDF version: 98ad01e
  • Build System: idf.py
  • Power Supply: USB

Problem Description

esp_hid_host example doesn't connect to BT classic keyboard. Authentication failure.

Expected Behavior

It should connect like it did for earlier version of the demo.

Actual Behavior

ESP32 sees keyboard. Nothing happens. After pressing enter authentication fails.

Steps to reproduce

  1. Check out 98ad01e
  2. Build flash and monitor the esp_hid_host example
  3. Power on an Apple Wireless Keyboard model A1314 (FCC ID: BCGA1314-IC-579C-A1314)
  4. Reset the ESP32 and see it connects with the keyboard
  5. Press any key, but not enter key and see nothing happens
  6. Press enter key and see authentication failure.

Code to reproduce this issue

esp_hid_host example

Debug Logs

I (2528) ESP_HIDH_DEMO: SCAN...
D (2538) event: running post ESP_HIDH_EVENTS:5 with handler 0x400d782c and context 0x3ffb7358 on loop 0x3ffca68c
0x400d782c: hidh_callback at build/../main/esp_hid_host_main.c:33

V (2538) ESP_HID_GAP: BT GAP DISC_STATE START
I (2548) ESP_HIDH_DEMO: EVENT: 5
BT : 78:ca:39:49:c4:2a, COD: major: PERIPHERAL, minor: 16, service: 0x001, RSSI: -60
BT : 78:ca:39:49:c4:2a, BDNAME: Apple Wireless Keyboard
V (6518) ESP_HID_GAP: BT GAP DISC_STATE STOP
I (6518) ESP_HIDH_DEMO: SCAN: 1 result
BT : 78:ca:39:49:c4:2a, RSSI: -60, USAGE: GENERIC, COD: PERIPHERAL[KEYBOARD] srv 0x001, UUID16: 0x0000, NAME: Apple Wireless Keyboard
W (7118) BT_SDP: process_service_attr_rsp

W (7408) BT_SDP: process_service_attr_rsp

And after pressing return on the keyboard:

D (18098) nvs: nvs_open_from_partition bt_config.conf 1
D (18098) nvs: nvs_set_blob bt_cfg_key0 784
W (18108) BT_BTM: btm_sec_clr_temp_auth_service() - no dev CB

D (18118) nvs: nvs_close 4
E (18118) BT_BTC: btc_dm_auth_cmpl_evt() Authentication fail reason 5
V (18118) ESP_HID_GAP: BT GAP EVENT AUTH_CMPL
E (18118) BT_HIDH: OPEN ERROR: ERR_AUTH_FAILED
D (18128) event: running post ESP_HIDH_EVENTS:0 with handler 0x400d898c and context 0x3ffb7318 on loop 0x3ffca68c
0x400d898c: esp_hidh_process_event_data_handler at esp-idf/components/esp_hid/src/esp_hidh.c:817

D (18138) event: running post ESP_HIDH_EVENTS:0 with handler 0x400d782c and context 0x3ffb7358 on loop 0x3ffca68c
0x400d782c: hidh_callback at build/../main/esp_hid_host_main.c:33

E (18148) ESP_HIDH_DEMO: OPEN failed!

Other items if possible

workaround

Use stable version of IDF, version 4.3.1. The commit of September 8 80c3aaa broke the example.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 7, 2021
@github-actions github-actions bot changed the title esp_hid_host cannot connect to USB Keyboard: Authentication fail reason 5 esp_hid_host cannot connect to USB Keyboard: Authentication fail reason 5 (IDFGH-6368) Dec 7, 2021
@boernsen-development
Copy link

boernsen-development commented Oct 18, 2022

I tried to build the example from v4.3.1 (as you referred to that as workaround), but it doesn't build. How did you solve it?

[...]
[82/86] Linking C static library esp-idf/soc/libsoc.a
[83/86] Linking C static library esp-idf/hal/libhal.a
[84/86] Linking C static library esp-idf/main/libmain.a
[85/86] Linking C executable bootloader.elf
[86/86] Generating binary image from built executable
esptool.py v3.1-dev
Merged 1 ELF section
Generated /home/boernsen/eclipse-workspace/esp_hid_host_v431/build/bootloader/bootloader.bin
[663/1234] Generating x509_crt_bundle
/home/boernsen/.espressif/python_env/idf4.3_py3.8_env/lib/python3.8/site-packages/cryptography/x509/base.py:521: CryptographyDeprecationWarning: Parsed a negative serial number, which is disallowed by RFC 5280.
return rust_x509.load_pem_x509_certificate(data)
[1213/1234] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/esp_hid_host_main.c.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/esp_hid_host_main.c.obj
/home/boernsen/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -Iconfig -I../main -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/newlib/platform_include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/freertos/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/freertos/port/xtensa/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_hw_support/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_hw_support/port/esp32/. -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/heap/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/log/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/lwip/include/apps -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/lwip/include/apps/sntp -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/lwip/lwip/src/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/lwip/port/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/lwip/port/esp32/include/arch -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/soc/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/soc/esp32/. -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/soc/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/hal/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/hal/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_rom/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_rom/esp32 -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_rom/include/esp32 -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_common/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_system/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/driver/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/driver/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_ringbuf/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/efuse/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/efuse/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/xtensa/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/xtensa/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/espcoredump/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_timer/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_ipc/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_pm/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/vfs/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_wifi/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_wifi/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_event/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_netif/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_eth/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/tcpip_adapter/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/app_trace/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_hid/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/bt/common/osi/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/bt/include/esp32/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/bt/common/api/include/api -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/bt/common/btc/profile/esp/blufi/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/bt/common/btc/profile/esp/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/bt/host/bluedroid/api/include/api -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/nvs_flash/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/spi_flash/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/mbedtls/port/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/mbedtls/mbedtls/include -I/home/boernsen/esp-idf/v4.3.1/esp-idf/components/mbedtls/esp_crt_bundle/include -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER="v4.3.1" -DESP_PLATFORM -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/esp_hid_host_main.c.obj -MF esp-idf/main/CMakeFiles/__idf_main.dir/esp_hid_host_main.c.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/esp_hid_host_main.c.obj -c ../main/esp_hid_host_main.c
In file included from /home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_timer/include/esp_timer.h:45,
from /home/boernsen/esp-idf/v4.3.1/esp-idf/components/freertos/port/xtensa/include/freertos/portmacro.h:46,
from /home/boernsen/esp-idf/v4.3.1/esp-idf/components/freertos/include/freertos/portable.h:52,
from /home/boernsen/esp-idf/v4.3.1/esp-idf/components/freertos/include/freertos/FreeRTOS.h:64,
from ../main/esp_hid_host_main.c:11:
../main/esp_hid_host_main.c: In function 'app_main':
../main/esp_hid_host_main.c:131:54: error: 'esp_hidh_gattc_event_handler' undeclared (first use in this function); did you mean 'esp_hidh_event_data_t'?
ESP_ERROR_CHECK( esp_ble_gattc_register_callback(esp_hidh_gattc_event_handler) );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_common/include/esp_err.h:119:31: note: in definition of macro 'ESP_ERROR_CHECK'
esp_err_t __err_rc = (x);
^
../main/esp_hid_host_main.c:131:54: note: each undeclared identifier is reported only once for each function it appears in
ESP_ERROR_CHECK( esp_ble_gattc_register_callback(esp_hidh_gattc_event_handler) );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/boernsen/esp-idf/v4.3.1/esp-idf/components/esp_common/include/esp_err.h:119:31: note: in definition of macro 'ESP_ERROR_CHECK'
esp_err_t __err_rc = (x);
^
[1222/1234] Building C object esp-idf/libsodium/CMa...odium/crypto_core/ed25519/ref10/ed25519_ref10.c.obj
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

@ChrisIdema
Copy link
Author

@boernsen-development Did you update the submodules recursively? You need the right commits of the submodules.

@boernsen-development
Copy link

boernsen-development commented Oct 18, 2022

I followed the Get Started Guide for v4.2.4 for Linux, but adapted the clone command to: git clone -b v4.3.1 --recursive https://github.com/espressif/esp-idf.git

I faced the same build error with v4.2.4 itself (exactly following the guide).

With v4.4.2 it built successfully, but pairing failed.

@xiongweichao
Copy link
Collaborator

Hi @boernsen-development ,

Please check if GATTC is enabled (CONFIG_GATTC_ENABLE=y).
If you still have problems, please provide sdkconfig.

Thanks

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Oct 19, 2022
@boernsen-development
Copy link

boernsen-development commented Oct 21, 2022

@xiongweichao with your advice, it now builds. Thank you!! (I used to deactivate BLE, but that apparently broke the build for v4.3.1. In the master branch it works.)

However, it still doesn't pair with the trackpad. It finds it, but prints an error. Tested with ESP-IDF v4.2.4 and v4.3.1:

I (13237) ESP_HIDH_DEMO: SCAN: 1 results
BT : aa:bb:cc:dd:ee:ff, RSSI: -40, USAGE: GENERIC, COD: PERIPHERAL[MOUSE+TABLET] srv 0x001, , NAME: Trackpad
W (15897) BT_SDP: process_service_attr_rsp

W (16177) BT_SDP: process_service_attr_rsp

E (16327) BT_HIDH: OPEN ERROR: Device Not Found
W (16477) BT_HCI: DiscCmpl evt: hdl=129, rsn=0x5
E (16487) BT_APPL: bta_gattc_mark_bg_conn unable to find the bg connection mask for: aa:bb:cc:dd:ee:ff
E (16487) BT_BTC: btc_dm_auth_cmpl_evt() Authentication fail reason 5

Maybe it is a different issue than the one from @ChrisIdema. In that case, we can continue at #10005 .

@f1ac0
Copy link

f1ac0 commented Oct 28, 2022

This is not exactly the same error message, however the effect is similar.

With esp_hid_host example and esp-idf-v4.4 dated 2022-01-26 downloaded from the espressif website (from home page : Support -> Download -> "SDKs & Demos"), trying to connect a hid device results in :
E (11012) BT_BTM: tBTM_SEC_DEV:0x3ffb73fc rs_disc_pending=0 E (11902) BT_HIDH: OPEN ERROR: ERR_SDP E (11902) ESP_HIDH_DEMO: OPEN failed! W (11992) BT_HIDH: HID-Host Rcvd L2CAP disc cfm, unknown CID: 0x42 W (14512) BT_L2CAP: L2CAP - unknown CID: 0x9ff0

The same example code compiled with esp-idf-v4.4.2 (the last stable downloaded from github when writing this message) works fine.

It might be a good idea either to update the package in the download section of the website or remove it/replace it with a link to the github page ?

@f1ac0
Copy link

f1ac0 commented Oct 29, 2022

Well, some more tests show that even if esp-idf-v4.4.2 works with some devices with the esp_hid_host example, others do not work with the same "Authentication fail reason 5" explained by the original report by ChrisIdema. One of these devices is the Wiimote RVL-CNT-01.

With esp-idf-v4.3.1 proposed as workaround, the esp_hid_host example has no issue with these devices and show the events data as expected.

@espressif-bot espressif-bot added Resolution: Done Issue is done internally Status: Done Issue is done internally and removed Status: In Progress Work is in progress labels Mar 22, 2023
@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting and sharing the updates, feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

7 participants