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 fails to pair with BT Classic 2.0 trackpad or mouse: Authentication fail reason 5 (IDFGH-8555) #10005

Closed
3 tasks done
boernsen-development opened this issue Oct 18, 2022 · 11 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@boernsen-development
Copy link

boernsen-development commented Oct 18, 2022

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1-dev-1390-g6a8810fa39

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

No response

Development Kit.

ESP32 Dev Kit C V4

Power Supply used.

USB

What is the expected behavior?

I expected the esp_hid_host demo to successfully pair with my BT Classic 2.0 trackpad or mouse. If it doesn't pair I expect it to print an informative error or reference to further documentation for help to debug this.

What is the actual behavior?

Instead it prints:

E (11403) BT_HIDH: OPEN ERROR: ERR
E (11403) ESP_HIDH_DEMO: OPEN failed!
W (11553) BT_HCI: hcif disc complete: hdl 0x81, rsn 0x5
E (11553) BT_APPL: bta_gattc_mark_bg_conn unable to find the bg connection mask for: aa:bb:cc:dd:ee:ff
E (11563) BT_BTC: btc_dm_auth_cmpl_evt() Authentication fail reason 5

Steps to reproduce.

  1. Check out 6a8810f
  2. Build, flash and monitor esp_hid_host example (Optionally deactivate BLE via idf.py menuconfig before building)
  3. Put the BT Classic trackpad or mouse into pairing mode (I used an Apple Magic Trackpad 1. gen and an Apple Magic Mouse)
  4. Reset the ESP32
  5. ESP32 scan seems to find the trackpad / mouse and it tries to connect (Note that the trackpad has a default passkey 0000, but I am never asked for it. The Apple Magic Mouse has no pairing passkey.)
  6. BT_HIDH: OPEN ERROR: ERR

Debug Logs.

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7024
load:0x40078000,len:15400
load:0x40080400,len:3816
0x40080400: _init at ??:?

entry 0x40080648
I (27) boot: ESP-IDF v5.1-dev-1390-g6a8810fa39 2nd stage bootloader
I (27) boot: compile time Oct 21 2022 19:03:47
I (29) boot: chip revision: V300
I (33) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 3, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=25a70h (154224) map
I (168) esp_image: segment 1: paddr=00035a98 vaddr=3ffbdb60 size=04948h ( 18760) load
I (176) esp_image: segment 2: paddr=0003a3e8 vaddr=40080000 size=05c30h ( 23600) load
I (186) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=98010h (622608) map
I (411) esp_image: segment 4: paddr=000d8038 vaddr=40085c30 size=11a20h ( 72224) load
I (441) esp_image: segment 5: paddr=000e9a60 vaddr=50000000 size=00010h (    16) load
I (453) boot: Loaded app from partition at offset 0x10000
I (453) boot: Disabling RNG early entropy source...
I (465) cpu_start: Pro cpu up.
I (465) cpu_start: Starting app cpu, entry point is 0x400812e0
0x400812e0: call_start_cpu1 at /home/ben/esp-idf/master/esp-idf/components/esp_system/port/cpu_start.c:146

I (0) cpu_start: App cpu up.
I (481) cpu_start: Pro cpu start user code
I (481) cpu_start: cpu freq: 160000000 Hz
I (481) cpu_start: Application information:
I (486) cpu_start: Project name:     esp_hid_host
I (491) cpu_start: App version:      90e411a
I (496) cpu_start: Compile time:     Oct 22 2022 11:29:24
I (502) cpu_start: ELF file SHA256:  2e3976d005f76386...
I (508) cpu_start: ESP-IDF:          v5.1-dev-1390-g6a8810fa39
I (515) heap_init: Initializing. RAM available for dynamic allocation:
I (522) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (528) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (534) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (540) heap_init: At 3FFC82C8 len 00017D38 (95 KiB): DRAM
I (546) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (553) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (559) heap_init: At 40097650 len 000089B0 (34 KiB): IRAM
I (567) spi_flash: detected chip: generic
I (570) spi_flash: flash io: dio
W (574) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (588) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (623) ESP_HIDH_DEMO: setting hid gap, mode:3
I (633) BTDM_INIT: BT controller compile version [8020d24]
I (633) system_api: Base MAC address is not set
I (633) system_api: read default base MAC address from EFUSE
I (643) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (1353) ESP_HIDH_DEMO: EVENT: 5
I (1363) ESP_HIDH_DEMO: SCAN...
BLE: zz:zz:zz:zz:zz:zz, RSSI: -89, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: xx:xx:xx:xx:xx:xx, RSSI: -92, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -35
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -34
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -36
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -35
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -34
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -35
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -35
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -35
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -35
BT : aa:bb:cc:dd:ee:ff, BDNAME: Apple Magic Trackpad
I (10353) ESP_HIDH_DEMO: SCAN: 1 results
  BT : aa:bb:cc:dd:ee:ff, RSSI: -35, USAGE: GENERIC, COD: PERIPHERAL[MOUSE+TABLET] srv 0x001, UUID16: 0x0000, NAME: Apple Magic Trackpad 
W (10753) BT_HCI: hcif conn complete: hdl 0x81, st 0x0
W (10923) BT_SDP: process_service_attr_rsp

W (11203) BT_SDP: process_service_attr_rsp

E (11403) BT_HIDH: OPEN ERROR: ERR
E (11403) ESP_HIDH_DEMO:  OPEN failed!
W (11553) BT_HCI: hcif disc complete: hdl 0x81, rsn 0x5
E (11553) BT_APPL: bta_gattc_mark_bg_conn unable to find the bg connection mask for: aa:bb:cc:dd:ee:ff
E (11563) BT_BTC:  btc_dm_auth_cmpl_evt() Authentication fail reason 5

More Information.

Possibly related to #8027.

@boernsen-development boernsen-development added the Type: Bug bugs in IDF label Oct 18, 2022
@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 18, 2022
@github-actions github-actions bot changed the title esp_hid_host fails to pair with BT Classic 2.0 trackpad: Authentication fail reason 5 esp_hid_host fails to pair with BT Classic 2.0 trackpad: Authentication fail reason 5 (IDFGH-8555) Oct 18, 2022
@boernsen-development
Copy link
Author

The workaround from #8027 (i.e. using ESP-IDF v4.3.1) did not work (see comment), so this might be a different issue here.

@boernsen-development
Copy link
Author

Could it have something to do with the pairing passkey/PIN of the trackpad? It has a default configured passkey 0000 and I can't change it. When running the demo I am never asked about a passkey, nor did I configure anything related.

@boernsen-development
Copy link
Author

boernsen-development commented Oct 22, 2022

Update to latest master commit and test with an Apple Magic Mouse (no passkey!): same result

I (13353) ESP_HIDH_DEMO: SCAN: 1 results
BT : aa:bb:cc:dd:ee:ff, RSSI: -51, USAGE: GENERIC, COD: PERIPHERAL[MOUSE] srv 0x001, UUID16: 0x0000, NAME: Apple Magic Mouse
W (17793) BT_HCI: hcif conn complete: hdl 0x81, st 0x0
W (17923) BT_SDP: process_service_attr_rsp

W (18183) BT_SDP: process_service_attr_rsp

E (18363) BT_HIDH: OPEN ERROR: ERR
E (18363) ESP_HIDH_DEMO: OPEN failed!
W (18503) BT_HCI: hcif disc complete: hdl 0x81, rsn 0x5
E (18513) BT_APPL: bta_gattc_mark_bg_conn unable to find the bg connection mask for: aa:bb:cc:dd:ee:ff
E (18523) BT_BTC: btc_dm_auth_cmpl_evt() Authentication fail reason 5

With v4.3.1:

I (6316) ESP_HIDH_DEMO: SCAN: 1 results
BT : aa:bb:cc:dd:ee:ff, RSSI: -33, USAGE: GENERIC, COD: PERIPHERAL[MOUSE] srv 0x001, , NAME: Apple Magic Mouse
W (10526) BT_SDP: process_service_attr_rsp

W (10776) BT_SDP: process_service_attr_rsp

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

So far I could only test Apple products as I don't have any other devices available right now. It would be interesting to see whether the same happens with a BT mouse/keyboard of a different brand, just to rule out brand specific reasons. The pairing passkey apparently doesn't change anything.

Updated first post accordingly.

@boernsen-development boernsen-development changed the title esp_hid_host fails to pair with BT Classic 2.0 trackpad: Authentication fail reason 5 (IDFGH-8555) esp_hid_host fails to pair with BT Classic 2.0 trackpad or mouse: Authentication fail reason 5 (IDFGH-8555) Oct 22, 2022
@BetterJincheng
Copy link
Collaborator

@boernsen-development Please try with

static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
    ESP_LOGW(TAG, "==> BT GAP EVENT %s", bt_gap_evt_str(event));

    switch (event) {
    case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: {
        ESP_LOGV(TAG, "BT GAP DISC_STATE %s", (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED) ? "START" : "STOP");
        if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) {
            SEND_BT_CB();
        }
        break;
    }
    case ESP_BT_GAP_DISC_RES_EVT: {
        handle_bt_device_result(&param->disc_res);
        break;
    }
    case ESP_BT_GAP_KEY_NOTIF_EVT:
        ESP_LOGI(TAG, "BT GAP KEY_NOTIF passkey:%d", param->key_notif.passkey);
        break;
    case ESP_BT_GAP_MODE_CHG_EVT:
        ESP_LOGI(TAG, "BT GAP MODE_CHG_EVT mode:%d", param->mode_chg.mode);
        break;
    case ESP_BT_GAP_CFM_REQ_EVT:
        ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
        esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
        break;
    default:
        ESP_LOGV(TAG, "BT GAP EVENT %s", bt_gap_evt_str(event));
        break;
    }
}

Please attach the logs with modified bt_gap_event_handler() in examples/bluetooth/esp_hid_host/main/esp_hid_gap.c.

@boernsen-development
Copy link
Author

boernsen-development commented Oct 26, 2022

Thank you for your response @BetterJincheng !

I tried that and got this build error with the code above:

../main/esp_hid_gap.c:411:18: error: 'BT_AV_TAG' undeclared (first use in this function)

So I replaced BT_AV_TAG by TAG.
Hope this was correct?

This is the error log I get:

E (12391) BT_HIDH: OPEN ERROR: ERR
E (12391) ESP_HIDH_DEMO: OPEN failed!
W (12541) BT_HCI: hcif disc complete: hdl 0x81, rsn 0x5
E (12541) BT_APPL: bta_gattc_mark_bg_conn unable to find the bg connection mask for: aa:bb:cc:dd:ee:ff
E (12551) BT_BTC: btc_dm_auth_cmpl_evt() Authentication fail reason 5
W (12551) ESP_HID_GAP: ==> BT GAP EVENT AUTH_CMPL

Does this help? Please let me know if you need more.

@BetterJincheng
Copy link
Collaborator

BetterJincheng commented Oct 27, 2022

@boernsen-development I guess I have located the problem. Please test again with:

static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
    switch (event) {
    case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: {
        ESP_LOGV(TAG, "BT GAP DISC_STATE %s", (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED) ? "START" : "STOP");
        if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED) {
            SEND_BT_CB();
        }
        break;
    }
    case ESP_BT_GAP_DISC_RES_EVT: {
        handle_bt_device_result(&param->disc_res);
        break;
    }
    case ESP_BT_GAP_KEY_NOTIF_EVT:
        ESP_LOGI(TAG, "BT GAP KEY_NOTIF passkey:%d", param->key_notif.passkey);
        break;
    case ESP_BT_GAP_MODE_CHG_EVT:
        ESP_LOGI(TAG, "BT GAP MODE_CHG_EVT mode:%d", param->mode_chg.mode);
        break;
    case ESP_BT_GAP_PIN_REQ_EVT:
        ESP_LOGI(TAG, "BT GAP MODE_CHG_EVT mode:%d", param->mode_chg.mode);
        if (param->pin_req.min_16_digit) {
            ESP_LOGI(TAG, "Input pin code: 0000 0000 0000 0000");
            esp_bt_pin_code_t pin_code = {0};
            esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
        } else {
            ESP_LOGI(TAG, "Input pin code: 1234 or 0000");
            esp_bt_pin_code_t pin_code;
            /* this type */
            pin_code[0] = '1';
            pin_code[1] = '2';
            pin_code[2] = '3';
            pin_code[3] = '4';
            /* or, this type */
            // pin_code[0] = '0';
            // pin_code[1] = '0';
            // pin_code[2] = '0';
            // pin_code[3] = '0';
            esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
        }
        break;
    default:
        ESP_LOGV(TAG, "BT GAP EVENT %s", bt_gap_evt_str(event));
        break;
    }
}

and

static esp_err_t init_bt_gap(void)
{
    esp_err_t ret;
    // esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
    // esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
    // esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
    /*
     * Set default parameters for Legacy Pairing
     * Use fixed pin code
     */
    esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_VARIABLE;
    esp_bt_pin_code_t pin_code;
    esp_bt_gap_set_pin(pin_type, 0, pin_code);

    if ((ret = esp_bt_gap_register_callback(bt_gap_event_handler)) != ESP_OK) {
        ESP_LOGE(TAG, "esp_bt_gap_register_callback failed: %d", ret);
        return ret;
    }

    // Allow BT devices to connect back to us
    if ((ret = esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_NON_DISCOVERABLE)) != ESP_OK) {
        ESP_LOGE(TAG, "esp_bt_gap_set_scan_mode failed: %d", ret);
        return ret;
    }
    return ret;
}

Wait for your reply.
Thanks!

@BetterJincheng
Copy link
Collaborator

BetterJincheng commented Oct 27, 2022

@boernsen-development As your device is BT Classic 2.0 which does not support Secure Simple Paring and use a FIXED PIN CODE. In this way, we let HOST to reply the specific pin code '0000' or '1234'.

@boernsen-development
Copy link
Author

boernsen-development commented Oct 27, 2022

@BetterJincheng Thank you for the good idea!

I indeed got one step further now. Actually, I tried to turn off Secure Simple Pairing from idf.py menuconfig before, but that fails to build --> #10069

Anyway, with your changes there is a new error now. Here is full log:

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7024
load:0x40078000,len:15400
load:0x40080400,len:3816
0x40080400: _init at ??:?

entry 0x40080648
I (27) boot: ESP-IDF v5.1-dev-1401-gae30c509ef 2nd stage bootloader
I (27) boot: compile time Oct 27 2022 20:14:49
I (29) boot: chip revision: V300
I (33) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 3, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=25ae0h (154336) map
I (168) esp_image: segment 1: paddr=00035b08 vaddr=3ffbdb60 size=04940h ( 18752) load
I (176) esp_image: segment 2: paddr=0003a450 vaddr=40080000 size=05bc8h ( 23496) load
I (186) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=980b0h (622768) map
I (411) esp_image: segment 4: paddr=000d80d8 vaddr=40085bc8 size=11a88h ( 72328) load
I (441) esp_image: segment 5: paddr=000e9b68 vaddr=50000000 size=00010h (    16) load
I (453) boot: Loaded app from partition at offset 0x10000
I (453) boot: Disabling RNG early entropy source...
I (465) cpu_start: Pro cpu up.
I (465) cpu_start: Starting app cpu, entry point is 0x400812e0
0x400812e0: call_start_cpu1 at /home/boernsen/esp-idf/master/esp-idf/components/esp_system/port/cpu_start.c:146

I (0) cpu_start: App cpu up.
I (481) cpu_start: Pro cpu start user code
I (481) cpu_start: cpu freq: 160000000 Hz
I (481) cpu_start: Application information:
I (486) cpu_start: Project name:     esp_hid_host
I (491) cpu_start: App version:      4cba8c8-dirty
I (497) cpu_start: Compile time:     Oct 27 2022 20:14:40
I (503) cpu_start: ELF file SHA256:  338d334c51055515...
I (509) cpu_start: ESP-IDF:          v5.1-dev-1401-gae30c509ef
I (516) heap_init: Initializing. RAM available for dynamic allocation:
I (523) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (529) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (535) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (541) heap_init: At 3FFC82C0 len 00017D40 (95 KiB): DRAM
I (547) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (553) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (560) heap_init: At 40097650 len 000089B0 (34 KiB): IRAM
I (568) spi_flash: detected chip: generic
I (571) spi_flash: flash io: dio
W (575) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (589) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (621) ESP_HIDH_DEMO: setting hid gap, mode:3
I (621) BTDM_INIT: BT controller compile version [8020d24]
I (631) system_api: Base MAC address is not set
I (631) system_api: read default base MAC address from EFUSE
I (641) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (1341) ESP_HIDH_DEMO: EVENT: 5
I (1341) ESP_HIDH_DEMO: SCAN...
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -43
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -50
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -43
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -51
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -41
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -45
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -41
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -50
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -42
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -50
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -42
BT : aa:bb:cc:dd:ee:ff, COD: major: PERIPHERAL, minor: 37, service: 0x001, RSSI: -41
BT : aa:bb:cc:dd:ee:ff, BDNAME: Trackpad
I (10831) ESP_HIDH_DEMO: SCAN: 1 results
  BT : aa:bb:cc:dd:ee:ff, RSSI: -41, USAGE: GENERIC, COD: PERIPHERAL[MOUSE+TABLET] srv 0x001, UUID16: 0x0000, NAME: Trackpad 
W (11271) BT_HCI: hcif conn complete: hdl 0x81, st 0x0
W (11411) BT_SDP: process_service_attr_rsp

W (11721) BT_SDP: process_service_attr_rsp

I (11791) ESP_HID_GAP: BT GAP MODE_CHG_EVT mode:0
I (11791) ESP_HID_GAP: Using pin code: 0000
W (12001) BT_APPL: new conn_srvc id:23, app_id:1
I (12011) ESP_HIDH_DEMO: aa:bb:cc:dd:ee:ff OPEN: 
BDA:aa:bb:cc:dd:ee:ff, Status: OK, Connected: YES, Handle: 0, Usage: MOUSE
Name: , Manufacturer: , Serial Number: 
PID: 0x030e, VID: 0x05ac, VERSION: 0x0160
Report Map Length: 116
    VENDOR   INPUT REPORT, ID:  19, Length:   1
    VENDOR FEATURE REPORT, ID:  85, Length:  64
   GENERIC FEATURE REPORT, ID:  71, Length:   1
     MOUSE   INPUT   BOOT, ID:   2, Length:   3
     MOUSE   INPUT REPORT, ID:   2, Length:   3
E (12181) BT_HIDH: Not find report handle: 0 mode: REPORT
E (12181) BT_HIDH: Not find report handle: 0 mode: REPORT
W (12321) BT_HCI: hcif mode change: hdl 0x81, mode 2, intv 18, status 0x0
I (12321) ESP_HID_GAP: BT GAP MODE_CHG_EVT mode:2
E (12421) BT_HIDH: Not find report handle: 0 mode: REPORT

Do you have an idea how to solve that? (Should I open a new issue?)
Update: Apparently, this means it is connected right? :)

@boernsen-development
Copy link
Author

boernsen-development commented Oct 27, 2022

I also don't understand why I got the same original error with the Apple Magic Mouse (which has no PIN). However, with the latest master I realized the Magic Mouse seems to connect. So I tried again with the Trackpad.

After I changed the pin_code from esp_hid_gap.c from originally 1,2,3,4 to 0,0,0,0 (everything else is original from the master commit bd18096):

static esp_err_t init_bt_gap(void)
{
    esp_err_t ret;
    esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
    esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
    esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
    /*
     * Set default parameters for Legacy Pairing
     * Use fixed pin code
     */
    esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_FIXED;
    esp_bt_pin_code_t pin_code;
    pin_code[0] = '0';
    pin_code[1] = '0';
    pin_code[2] = '0';
    pin_code[3] = '0';
    esp_bt_gap_set_pin(pin_type, 4, pin_code);

    if ((ret = esp_bt_gap_register_callback(bt_gap_event_handler)) != ESP_OK) {
        ESP_LOGE(TAG, "esp_bt_gap_register_callback failed: %d", ret);
        return ret;
    }

    // Allow BT devices to connect back to us
    if ((ret = esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_NON_DISCOVERABLE)) != ESP_OK) {
        ESP_LOGE(TAG, "esp_bt_gap_set_scan_mode failed: %d", ret);
        return ret;
    }
    return ret;
}

It actually connects!!! (at least most of the time)

@BetterJincheng
Copy link
Collaborator

@boernsen-development I think you can open a new issue to solve the new problem. Thanks!

@boernsen-development
Copy link
Author

boernsen-development commented Oct 28, 2022

@BetterJincheng Thank you very much for all your help!

I'm actually very confused now. With the latest master (2d9e75b), it all works without any changes. However, after that I tried release v5.0 and it also works!! I don't get why as I was sure I did try various versions. Also it doesn't ask for a PIN and the only PIN I can find in the sources is 1234 whereas the trackpad actually has PIN 0000. Still it connects with both versions no matter if I deactivate Simple Pairing Mode or not... (To build with deactivated Simple Pairing Mode, I still need the workaround from #10069)

I actually felt I was quiet meticulous when testing to avoid overseeing anything. The only explanations I can come up with are:

  • Maybe I did something different when putting the trackpad into pairing mode. Recently, after using the power button to put the trackpad into pairing mode, I tend to hold down the power button while the LED blinks indicating pairing mode. Maybe that deactivates the PIN for that time or changes the pairing behavior? I don't know as there is no proper documentation... shame on Apple
  • Maybe the trackpad behaves differently to the ESP32 after it has been successfully paired once.

Quiet mysterious for me...

@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new Resolution: NA Issue resolution is unavailable labels Nov 24, 2022
espressif-bot pushed a commit that referenced this issue Nov 24, 2022
…authentication failure

2. provide compatibilities with devices that do not support Secure Simple Paring

Closes #10069
Closes #10005
espressif-bot pushed a commit that referenced this issue Nov 24, 2022
…authentication failure

2. provide compatibilities with devices that do not support Secure Simple Paring

Closes #10069
Closes #10005
espressif-bot pushed a commit that referenced this issue Nov 24, 2022
…authentication failure

2. provide compatibilities with devices that do not support Secure Simple Paring

Closes #10069
Closes #10005
espressif-bot pushed a commit that referenced this issue Dec 4, 2022
…authentication failure

2. provide compatibilities with devices that do not support Secure Simple Paring

Closes #10069
Closes #10005
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 Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants