MTU size is not getting updated with Android

I have a custom hardware running on nrf52840 and using ncs 2.6.1. I have implemented a custom authentication flow with customer characteristic along with the BLE bonding. I have a custom app for iOS and Android both. I tested my device pairing and bonding with my iOS app and its is working as expected. 

But when I test the same firmware with Android App I am facing issue with pairing. After the connection the device is not able to complete the BLE pairing somehow. To identify the actual issue I debug the operation and from the logs I found that the MTU size is not getting updated when I connect the device with the Android. And that is why my customer service that performs the authentication is not executed.


Regarding to the mobile app that I am using, both the apps are built on the same platform and well tested. And I have another application which is running on legacy Nordic SDK RTOS which is working fine with both the App android and iOS on the same hardware. And my existing application is the Zephyr revision of this legacy application.

So I suspect there is something that is missing after adding the Zephyr as the Application and Hardware both performing well but the same code with Zephyr is creating issue. Below are the application details.

prj.conf

CONFIG_BT=y
CONFIG_BT_SMP=y
CONFIG_BT_SMP_APP_PAIRING_ACCEPT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="LP"
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=7
CONFIG_BLE_NAME_AS_PER_MAC=y

CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DYNAMIC_DB=y

CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

CONFIG_BT_BONDING_FEATURE=y
CONFIG_BT_SETTINGS=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y
CONFIG_BT_MAX_PAIRED=5
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y

CONFIG_BT_USER_PHY_UPDATE=y
CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_AUTO_PHY_UPDATE=n
CONFIG_BT_ATT_PREPARE_COUNT=2
CONFIG_BT_BUF_ACL_TX_COUNT=10

iOS App pairing logs (Running on iPad iPadOS version 18.3.2)

00> I: Updated MTU: TX: 23 RX: 23 bytes
00> I: Current address: 6D:A0:99:63:55:47 (random)
00> I: Connected 6D:A0:99:63:55:47 (random)
00> I: Initialize iv :: 
00> I: LE PHY updated: TX PHY LE 2M, RX PHY LE 2M
00> I: LE data len updated: TX (len: 251 time: 2120) RX (len: 251 time: 2120)
00> W: Ignoring data for unknown channel ID 0x003a
00> I: Updated MTU: TX: 527 RX: 247 bytes
00> I: Security changed: 6D:A0:99:63:55:47 (random) level 2
00> I: Pairing completed: 20:15:82:15:8F:2A (public), bonded: 1

Android App pairing logs (Running on Android tablet version 14)

00> I: Updated MTU: TX: 23 RX: 23 bytes
00> I: Current address: 24:F0:D3:EF:99:EE (public)
00> I: Connected 24:F0:D3:EF:99:EE (public)
00> I: Initialize iv :: 
00> I: LE data len updated: TX (len: 251 time: 2120) RX (len: 27 time: 328)
00> I: Connection parameters updated:
00>  interval=7.50 ms, latency=0, timeout=5000 ms
00> I: Connection parameters updated:
00>  interval=45.00 ms, latency=0, timeout=5000 ms
00> I: Security failed: 24:F0:D3:EF:99:EE (public) level 1 err 4
00> I: Pairing failed conn: 24:F0:D3:EF:99:EE (public), reason 4
00> I: Disconnected from 24:F0:D3:EF:99:EE (public) (reason 19)

I am using BLE bonding with security

bt_conn_set_security(conn, BT_SECURITY_L2); with 
                                                       
static struct bt_conn_auth_cb conn_auth_callbacks = {
    .cancel = auth_cancel,
};
Can you please help me with this issue? Is there any known issue in the BLE MTU size update, specifically with Android?
Parents
  • Hi Ankit, 
    Error 4 you got () means 

    BT_SECURITY_ERR_AUTH_REQUIREMENT 

    /** The requested security level could not be reached. */
    Which security level did you request from the peripheral ? Or did you request pairing from the central ?
    We would need to have a sniffer trace to see what exactly happens between the 2 devices. 

    I don't see a reason why MTU updating would cause pairing to fail. 
Reply
  • Hi Ankit, 
    Error 4 you got () means 

    BT_SECURITY_ERR_AUTH_REQUIREMENT 

    /** The requested security level could not be reached. */
    Which security level did you request from the peripheral ? Or did you request pairing from the central ?
    We would need to have a sniffer trace to see what exactly happens between the 2 devices. 

    I don't see a reason why MTU updating would cause pairing to fail. 
Children
  • Hi,

    Thanks for the reply.

    I used bonding with bt_conn_set_security(conn, BT_SECURITY_L2); with below authentication callbacks 

    static struct bt_conn_auth_cb conn_auth_callbacks = {
        .cancel = auth_cancel,
    };

    With this configuration, the App will have a pop-up to pair or cancel after the connection. The disconnect happens from the App side, as you see the reason 19.

    The flow of operation is designed in such a way that if the App does not get the data from the sensor as part of authentication, it will disconnect the sensor and declare a failure.

    The app tries to read the characteristic data, but it does not fit into the MTU requirement; hence, it tries to update the MTU, but somehow the request is not reaching the sensor.

    Meanwhile, I will get some logs from the sniffer tool to understand the issue more.

  • I suspect that the Android phone was paired with your device before. You may want to try erase everything  (chip erase or click on the double arrow when you flash) to make sure the device delete all bond before testing. 
    If you want to allow a device to re-pair at security level 2 , you would need to enable this: CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y

Related