Bluetooth Classic: btc_bt_set_scan_mode not completely implemented?

esp32dummy
Posts: 4
Joined: Mon Mar 28, 2022 11:51 am

Bluetooth Classic: btc_bt_set_scan_mode not completely implemented?

Postby esp32dummy » Tue May 14, 2024 7:58 am

I've implemented A2DP sink for a commercial product which is working fine so far except pairing process. I understand that it is possible to call btc_bt_set_can_mode to set device being discoverable or not and also being connectable or not. So in normal operation state I want ESP32 to be connectable by paired devices only and not to be discoverable in that time. Therefore I call

Code: Select all

esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_NON_DISCOVERABLE)
To allow a new pairing, I set

Code: Select all

esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE)
for 30 seconds. This works fine, but there it is also possible to pair another device even in the time device is not discoverable. But it is required that a device can only pair in that specific time and connections to paired devices are allowed only.
I'm wondering if this feature isn't implemented yet for some reason, because implementation of esp_bt_gap_set_scan_mode() looks like this:

Code: Select all

static void btc_bt_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode)
{
    tBTA_DM_DISC disc_mode;
    tBTA_DM_CONN conn_mode;

    switch (c_mode) {
    case ESP_BT_NON_CONNECTABLE:
        conn_mode = BTA_DM_NON_CONN;
        break;
    case ESP_BT_CONNECTABLE:
        conn_mode = BTA_DM_CONN;
        break;
    default:
        BTC_TRACE_WARNING("invalid connection mode (0x%x)", c_mode);
        return;
    }

    switch (d_mode) {
    case ESP_BT_NON_DISCOVERABLE:
        disc_mode = BTA_DM_NON_DISC;
        break;
    case ESP_BT_LIMITED_DISCOVERABLE:
        disc_mode = BTA_DM_LIMITED_DISC;
        break;
    case ESP_BT_GENERAL_DISCOVERABLE:
        disc_mode = BTA_DM_GENERAL_DISC;
        break;
    default:
        BTC_TRACE_WARNING("invalid discovery mode (0x%x)", d_mode);
        return;
    }

    BTA_DmSetVisibility(disc_mode, conn_mode, BTA_DM_IGNORE, BTA_DM_IGNORE);
    return;
}
Above function calls BTA_DmSetVisibility() which has parameter pairable_mode and conn_filter. These parameters seem to provide exactly the functionality we are looking for. Unfortunately both are fixed set to BTA_DM_IGNORE, so they are not controllable via btc_bt_set_scan_mode(). For test purposes I set conn_filter to BTA_DM_CONN_PAIRED and it works a required. But we want to avoid to change ESP-IDF and so we are wondering if there is a reason that this functionality is not (yet) supported? We are using ESP-IDF v5.2.1.

Thanks,
Dennis

Who is online

Users browsing this forum: No registered users and 87 guests