This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BLE Disconnects with Samsung phones

Hi,

I am using nRF52840 and BLE coexistence (mesh and ble). I am able to connect to my board via BLE using nRFConnect for PC and a nRF52840-DK and change characteristics value, etc. I also implemented a static passkey and everything works fine with nRF Connect for PC and different phones (Googles, Blackview).

My problem is that it does not works with samsung phones such as Galaxy S7 or J5 : After 25s of connection it disconnects with the error "Error 8 (0x8): GATT CONN TIMEOUT" on the phone. If i try to read a characteristic, the passkey is requested and the phone disconnects right after sending the passkey with the same error.

Do you know from where this problem could come from ?

Parents
  • Hi,

    - Which SD and SDK have you built your application on?

    - Do you have an on-air sniffer log?

    - Can you also check the disconnect reason on the nRF52840? Should be passed with the BLE_GAP_EVT_DISCONNECT event in p_ble_evt->evt.gap_evt.params.disconnected.reason, I expect reason to be one of the Bluetooth status codes as listed in ble_hci.h.

    - You may try to comment out data_length_update(conn_handle, p_gatt); in on_connected_evt() in nrf_ble_gatt.c (or add a 100ms delay before calling it).

    Best regards,
    Kenneth

  • - My application is built on SDK 15.2.0, SDK For mesh V3.1.0, S140.

    - The disconnect reason i got is 0x22 : BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT

    - I tried to comment out data_length_update and it works fine with samsung phones but adding a 100ms delay before does not work. Should i keep it like that (with data_length_update commented) ?

    - I do not have an on-air sniffer log, is it possible to make one using a nrf52840-DK ?

  • Hi, i already have this case handling in ble_evt_handler in ble_softdevice_support.c :

    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                __PrintLog(LOG_MESH_APP, LOG_LEVEL_INFO, "[BLE]-> Connected \n"); 
                _t_BLEConfigService.u16_ConnHandle = p_ble_evt->evt.gap_evt.conn_handle;
                vBLEDRV_QwrConnHandleAssign();
    
                if (ptFLASHDRV_GetAnchorInfo()->b_AnchorConfiguredByBLE)
                {
                    vCS_RestoreConfigIntoCharacteristics(&_t_BLEConfigService);
                }
                break;
    
            case BLE_GAP_EVT_DISCONNECTED:
                __PrintLog(LOG_MESH_APP, LOG_LEVEL_INFO, "[BLE]-> Disconnected \n"); 
                // LED indication will be changed when advertising starts.
                _t_BLEConfigService.u16_ConnHandle = BLE_CONN_HANDLE_INVALID;
                vSYSCONFIG_ConfigSetConfiguredByBLE(true);
                ERROR_CHECK(u32FLASHDRV_StoreAnchorConfig());
                ERROR_CHECK(u32FLASHDRV_StoreServerInfo());
                __PrintLog(LOG_MESH_APP, LOG_LEVEL_INFO, "[BLE]-> Config stored, reset... \n"); 
                mesh_stack_device_reset();
                break;
    
            case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
            {
                __PrintLog(LOG_MESH_APP, LOG_LEVEL_INFO, "[BLE]-> PHY UPDATE REQUEST \n"); 
                ble_gap_phys_t const phys =
                {
                    .rx_phys = BLE_GAP_PHY_AUTO,
                    .tx_phys = BLE_GAP_PHY_AUTO,
                };
                err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
                APP_ERROR_CHECK(err_code);
            } break;
    
            case BLE_GATTC_EVT_TIMEOUT:
                // Disconnect on GATT Client timeout event.
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_TIMEOUT:
                // Disconnect on GATT Server timeout event.
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_WRITE:
                vCS_WriteEventCallback(&_t_BLEConfigService, p_ble_evt);
                break;
    
            case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
            {
                __PrintLog(LOG_MESH_APP, LOG_LEVEL_INFO, "[BLE]-> BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST \n"); 
    
                // Accepting parameters requested by peer.
                err_code = sd_ble_gap_conn_param_update(p_ble_evt->evt.gap_evt.conn_handle,
                                                        &p_ble_evt->evt.gap_evt.params.conn_param_update_request.conn_params);
                APP_ERROR_CHECK(err_code);
            }   
                break;
            default:
                // No implementation needed.
                break;
        }
    }

    Am i supposed to copy it somewhere else ?

  • I think a sniffer log would have solved this pretty quickly, but while waiting for an updated release (eta a few days):

    - Can you print out all p_ble_evt->header.evt_id just to check if there is any new events happening upon connection which differ between working and non working?

    - Search google for 'BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT' and see if you can find any relevant tips to try.

  • Here you can find what happens on both sides of the connection (phone and device) :

    For a blackview phone ( it works properly) :

    // BLACKVIEW PHONE : Connection, pairing and two characteristics reading before disconnection.
    
    <00:00:02>,[BLE]-> Fast advertising
    <00:02:55>,[BLE] Event -> 16 
    <00:02:55>,[BLE]-> Connected 
    <00:02:55>,ATT MTU exchange completed. central 0xF7 peripheral 0xF7 
    <00:02:55>,[BLE] Event -> 58 
    <00:02:55>,ATT MTU exchange completed. central 0xF7 peripheral 0xF7 
    <00:02:55>,[BLE] Event -> 36 
    <00:02:56>,[BLE] Event -> 18 
    <00:02:57>,[BLE] Event -> 18 
    <00:03:00>,Successfully updated connection parameters
    <00:03:00>,[BLE] Event -> 18 
    <00:03:29>,[BLE]-> UNKNOWN PM EVENT :1 
    <00:03:29>,[BLE]-> UNKNOWN PM EVENT :5 
    <00:03:29>,[BLE] Event -> 19 
    <00:03:29>,[BLE] Event -> 21 
    <00:03:30>,[BLE] Event -> 18 
    <00:03:38>,[BLE] Event -> 26 
    <00:03:38>,[BLE]-> UNKNOWN PM EVENT :2 
    <00:03:38>,[BLE] Event -> 25 
    <00:03:39>,Successfully updated connection parameters
    <00:03:39>,[BLE] Event -> 18 
    <00:03:40>,[BLE] Event -> 18 
    <00:03:42>,Successfully updated connection parameters
    <00:03:42>,[BLE] Event -> 18  
    <00:04:16>,Successfully updated connection parameters
    <00:04:16>,[BLE] Event -> 18 
    <00:04:21>,[BLE]-> Fast advertising
    <00:04:21>,[BLE] Event -> 17 
    <00:04:21>,[BLE]-> Disconnected 
    
    On phone side :
    
    nRF Connect, 2019-10-23
    Anchor  (CE:45:85:5E:08:37)
    nRF Connect, 2019-10-23
    Anchor  (CE:45:85:5E:08:37)
    V 10:37:30.366 Connecting to CE:45:85:5E:08:37...
    D 10:37:30.367 gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE)
    D 10:37:30.720 [Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I 10:37:30.720 Connected to CE:45:85:5E:08:37
    D 10:37:30.746 [Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
    V 10:37:30.783 Discovering services...
    D 10:37:30.783 gatt.discoverServices()
    D 10:37:32.264 [Callback] Services discovered with status: 0
    I 10:37:32.264 Services discovered
    V 10:37:32.305 Generic Access (0x1800)
    - Device Name [R W] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    - Central Address Resolution [R] (0x2AA6)
    Generic Attribute (0x1801)
    Nordic UART Service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
    - RX Characteristic [W WNR] (6e400002-b5a3-f393-e0a9-e50e24dcca9e)
    - TX Characteristic [N] (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
    Client Characteristic Configuration (0x2902)
    Unknown Service (d294c00f-df06-c4bf-0b4f-250b3adea514)
    - Unknown Characteristic [R W] (d294b013-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b016-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b019-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b016-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b01f-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b022-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b025-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b025-df06-c4bf-0b4f-250b3adea514)
    Characteristic User Description (0x2901)
    D 10:37:32.305 gatt.setCharacteristicNotification(6e400003-b5a3-f393-e0a9-e50e24dcca9e, true)
    V 10:38:03.833 Reading characteristic d294b013-df06-c4bf-0b4f-250b3adea514
    D 10:38:03.833 gatt.readCharacteristic(d294b013-df06-c4bf-0b4f-250b3adea514)
    D 10:38:05.229 [Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
    D 10:38:05.256 [Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_PIN (0)
    E 10:38:14.198 Error 137 (0x89): GATT AUTH FAIL
    D 10:38:14.255 [Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDED (12)
    I 10:38:14.255 Device bonded
    V 10:38:44.620 Reading characteristic d294b013-df06-c4bf-0b4f-250b3adea514
    D 10:38:44.620 gatt.readCharacteristic(d294b013-df06-c4bf-0b4f-250b3adea514)
    I 10:38:45.006 Read Response received from d294b013-df06-c4bf-0b4f-250b3adea514, value: (0x) 01
    A 10:38:45.006 "(0x) 01" received
    V 10:38:48.887 Reading characteristic d294b016-df06-c4bf-0b4f-250b3adea514
    D 10:38:48.887 gatt.readCharacteristic(d294b016-df06-c4bf-0b4f-250b3adea514)
    I 10:38:49.405 Read Response received from d294b016-df06-c4bf-0b4f-250b3adea514, value: (0x) 02
    A 10:38:49.405 "(0x) 02" received
    V 10:38:56.170 Disconnecting...
    D 10:38:56.170 gatt.disconnect()
    D 10:38:56.185 [Callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
    I 10:38:56.185 Disconnected
    D 10:38:57.223 [Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
    
    

    For a Samsung phone : it disconnects after a certain time after a connection or right after the pairing if i try pairing.

    // SAMSUNG PHONE : Disconnects after 10s of connection
    
    <00:18:51>,[BLE] Event -> 16 
    <00:18:51>,[BLE]-> Connected 
    <00:18:52>,ATT MTU exchange completed. central 0xF7 peripheral 0xF7 
    <00:18:52>,[BLE] Event -> 58 
    <00:18:52>,[BLE] Event -> 18 
    <00:18:52>,[BLE] Event -> 18 
    <00:18:57>,Successfully updated connection parameters
    <00:18:57>,[BLE] Event -> 18 
    <00:19:07>,[BLE]-> Fast advertising
    <00:19:07>,[BLE] Event -> 17 
    <00:19:07>,[BLE]-> Disconnected 
    
    On phone side :
    
    nRF Connect, 2019-10-23
    Anchor  (CE:45:85:5E:08:37)
    V	10:33:25.976	Connecting to CE:45:85:5E:08:37...
    D	10:33:25.976	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE)
    D	10:33:28.046	[Callback] Connection state changed with status: 133 and new state: DISCONNECTED (0)
    E	10:33:28.047	Error 133 (0x85): GATT ERROR
    I	10:33:28.047	Disconnected
    
    // SAMSUNG PHONE : Disconnects after pairing 
    
    <00:00:02>,[BLE]-> Fast advertising
    <00:00:19>,[BLE] Event -> 16 
    <00:00:19>,[BLE]-> Connected 
    <00:00:19>,ATT MTU exchange completed. central 0xF7 peripheral 0xF7 
    <00:00:19>,[BLE] Event -> 58 
    <00:00:20>,[BLE] Event -> 18 
    <00:00:20>,[BLE] Event -> 18 
    <00:00:23>,[BLE]-> UNKNOWN PM EVENT :1 
    <00:00:23>,[BLE]-> UNKNOWN PM EVENT :5 
    <00:00:23>,[BLE] Event -> 19 
    <00:00:23>,[BLE] Event -> 21 
    <00:00:24>,[BLE] Event -> 18 
    <00:00:30>,[BLE] Event -> 26 
    <00:00:30>,[BLE]-> UNKNOWN PM EVENT :2 
    <00:00:30>,[BLE] Event -> 25 
    <00:00:30>,Successfully updated connection parameters
    <00:00:30>,[BLE] Event -> 18 
    <00:00:31>,[BLE]-> Fast advertising
    <00:00:31>,[BLE] Event -> 17 
    <00:00:31>,[BLE]-> Disconnected 
    
    On phone side :
    
    nRF Connect, 2019-10-23
    Anchor  (CE:45:85:5E:08:37)
    V	10:33:25.976	Connecting to CE:45:85:5E:08:37...
    D	10:33:25.976	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE)
    D	10:33:28.046	[Callback] Connection state changed with status: 133 and new state: DISCONNECTED (0)
    E	10:33:28.047	Error 133 (0x85): GATT ERROR
    I	10:33:28.047	Disconnected
    D	10:34:19.508	gatt.close()
    D	10:34:19.511	wait(200)
    V	10:34:19.714	Connecting to CE:45:85:5E:08:37...
    D	10:34:19.715	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE)
    D	10:34:20.196	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I	10:34:20.196	Connected to CE:45:85:5E:08:37
    D	10:34:20.201	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
    D	10:34:20.221	wait(1600ms)
    V	10:34:21.836	Discovering services...
    D	10:34:21.836	gatt.discoverServices()
    D	10:34:21.864	[Callback] Services discovered with status: 0
    I	10:34:21.864	Services discovered
    V	10:34:21.927	Generic Access (0x1800)
    - Device Name [R W] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    - Central Address Resolution [R] (0x2AA6)
    Generic Attribute (0x1801)
    Nordic UART Service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
    - RX Characteristic [W WNR] (6e400002-b5a3-f393-e0a9-e50e24dcca9e)
    - TX Characteristic [N] (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
     Client Characteristic Configuration (0x2902)
    Unknown Service (d294c00f-df06-c4bf-0b4f-250b3adea514)
    - Unknown Characteristic [R W] (d294b013-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b016-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b019-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b016-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b01f-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b022-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b025-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (d294b025-df06-c4bf-0b4f-250b3adea514)
     Characteristic User Description (0x2901)
    D	10:34:21.927	gatt.setCharacteristicNotification(6e400003-b5a3-f393-e0a9-e50e24dcca9e, true)
    V	10:34:28.132	Reading characteristic d294b013-df06-c4bf-0b4f-250b3adea514
    D	10:34:28.132	gatt.readCharacteristic(d294b013-df06-c4bf-0b4f-250b3adea514)
    D	10:34:29.024	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
    D	10:34:29.046	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_PIN (0)
    E	10:34:32.132	Error 137 (0x89): GATT AUTH FAIL
    D	10:34:32.190	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDED (12)
    I	10:34:32.190	Device bonded
    D	10:34:36.793	[Callback] Connection state changed with status: 8 and new state: DISCONNECTED (0)
    E	10:34:36.793	Error 8 (0x8): GATT CONN TIMEOUT
    I	10:34:36.793	Disconnected
    D	10:34:36.931	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED

    I will look for BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT disconnection reason.

  • Can you on BLE_GAP_EVT_AUTH_STATUS (0x19 in hex) event read out the 'auth_status'. Likely equal one of these:

    /**@defgroup BLE_GAP_SEC_STATUS GAP Security status
     * @{ */
    #define BLE_GAP_SEC_STATUS_SUCCESS                0x00  /**< Procedure completed with success. */
    #define BLE_GAP_SEC_STATUS_TIMEOUT                0x01  /**< Procedure timed out. */
    #define BLE_GAP_SEC_STATUS_PDU_INVALID            0x02  /**< Invalid PDU received. */
    #define BLE_GAP_SEC_STATUS_RFU_RANGE1_BEGIN       0x03  /**< Reserved for Future Use range #1 begin. */
    #define BLE_GAP_SEC_STATUS_RFU_RANGE1_END         0x80  /**< Reserved for Future Use range #1 end. */
    #define BLE_GAP_SEC_STATUS_PASSKEY_ENTRY_FAILED   0x81  /**< Passkey entry failed (user canceled or other). */
    #define BLE_GAP_SEC_STATUS_OOB_NOT_AVAILABLE      0x82  /**< Out of Band Key not available. */
    #define BLE_GAP_SEC_STATUS_AUTH_REQ               0x83  /**< Authentication requirements not met. */
    #define BLE_GAP_SEC_STATUS_CONFIRM_VALUE          0x84  /**< Confirm value failed. */
    #define BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP       0x85  /**< Pairing not supported.  */
    #define BLE_GAP_SEC_STATUS_ENC_KEY_SIZE           0x86  /**< Encryption key size. */
    #define BLE_GAP_SEC_STATUS_SMP_CMD_UNSUPPORTED    0x87  /**< Unsupported SMP command. */
    #define BLE_GAP_SEC_STATUS_UNSPECIFIED            0x88  /**< Unspecified reason. */
    #define BLE_GAP_SEC_STATUS_REPEATED_ATTEMPTS      0x89  /**< Too little time elapsed since last attempt. */
    #define BLE_GAP_SEC_STATUS_INVALID_PARAMS         0x8A  /**< Invalid parameters. */
    #define BLE_GAP_SEC_STATUS_DHKEY_FAILURE          0x8B  /**< DHKey check failure. */
    #define BLE_GAP_SEC_STATUS_NUM_COMP_FAILURE       0x8C  /**< Numeric Comparison failure. */
    #define BLE_GAP_SEC_STATUS_BR_EDR_IN_PROG         0x8D  /**< BR/EDR pairing in progress. */
    #define BLE_GAP_SEC_STATUS_X_TRANS_KEY_DISALLOWED 0x8E  /**< BR/EDR Link Key cannot be used for LE keys. */
    #define BLE_GAP_SEC_STATUS_RFU_RANGE2_BEGIN       0x8F  /**< Reserved for Future Use range #2 begin. */
    #define BLE_GAP_SEC_STATUS_RFU_RANGE2_END         0xFF  /**< Reserved for Future Use range #2 end. */
    /**@} */
    

    Side question: Have you based your project on the ble app HID keyboard example in the SDK, since that one support bonding with passkey? Maybe check those parameters and compare with your own?

  • I did not based my project on this example since i already add my mesh and ble application but i used it as an example and it seems to me there is no big differences between them.

    Anyway, i changed softdevice to 6.1.1 and problem is solved like magic.

Reply Children
No Data
Related