Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Bluetooth SDK Forum Discussions

ToKo_4602001
Level 4
Level 4
50 sign-ins 25 replies posted 25 sign-ins

In the following code, I found that an incorrect value is returned as p_connection_status->reason.

----------------------------------------------------------------------------------------------------------------

wiced_bt_gatt_register(gatt_app_callback);

static wiced_bt_gatt_status_t fcl_gatt_app_callback(wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t *p_event_data){

  ble_connection_status(&p_event_data->connection_status);

...

...

}

static wiced_bt_gatt_status_t ble_connection_status(wiced_bt_gatt_connection_status_t *p_connection_status){

  if(p_connection_status->connected){

  ...

  }

else{

   printf("%x\n", p_connection_status->reason);

}

...

...

}

----------------------------------------------------------------------------------------------------------------

I think that it should be GATT_CONN_TERMINATE_PEER_USER or GATT_CONN_TERMINATE_LOCAL_HOST for normal disconnect, however "0": GATT_CONN_UNKNOWN will return when disconnect request is issued from a CYW20819 device by wiced_bt_gatt_disconnect().

I have confirmed that HCI event correctly indicated "reason" and gatt_app_callback() was called before this HCI message. So I assume that the callback is called at the timing of wiced_bt_gatt_disconnect() issued without reason code.

If we can regard GATT_CONN_UNKNOWN as a regular return code (GATT_CONN_TERMINATE_LOCAL_HOST), please let us know.

Thanks,

0 Likes
1 Solution

I checked the log from the stack with btspy. The stack reported the disconnect reason as 0x16 which means "connection terminated by local host".

It may because the disconnect command is sent from the application so the gatt disconnection event will report immediately. But the disconnection complete event from the stack is not reported yet. So the app level will take the GATT_UNKNOWN as the disconnection reason.

I will report it to the FW team. For your application, as the disconnection command is sent from the app, the application will know when this happens. You can take it as local host terminated the connection.

pastedImage_0.png

View solution in original post

4 Replies
Owen_Zhang123
Moderator
Moderator
Moderator
500 solutions authored 250 sign-ins 1000 replies posted

Do you know how the disconnection happened? Is it caused by the local host operation?

0 Likes

The disconnection happens by wiced_bt_gatt_disconnect() on local device in this case (incorrect reason code).

If the disconnection happens by peer/remote device, local device can receive correct reason code.

By the way, for abnormal disconnect (powered off of peer device, etc), correct reason code (0x08: Connection timeout) will return.

enum wiced_bt_gatt_disconn_reason_e {

    GATT_CONN_UNKNOWN                       = 0,                                    /* Unknown reason */

    GATT_CONN_L2C_FAILURE                   = 1,                                    /* General L2cap failure  */

    GATT_CONN_TIMEOUT                       = HCI_ERR_CONNECTION_TOUT,              /* Connection timeout  */

    GATT_CONN_TERMINATE_PEER_USER           = HCI_ERR_PEER_USER,                    /* Connection terminated by peer user  */

    GATT_CONN_TERMINATE_LOCAL_HOST          = HCI_ERR_CONN_CAUSE_LOCAL_HOST,        /* Connection terminated by local host  */

    GATT_CONN_FAIL_ESTABLISH                = HCI_ERR_CONN_FAILED_ESTABLISHMENT,    /* Connection fail to establish  */

    GATT_CONN_LMP_TIMEOUT                   = HCI_ERR_LMP_RESPONSE_TIMEOUT,         /* Connection fail due to LMP response tout */

    GATT_CONN_CANCEL                        = L2CAP_CONN_CANCEL                     /* L2CAP connection cancelled  */

};

0 Likes

I checked the log from the stack with btspy. The stack reported the disconnect reason as 0x16 which means "connection terminated by local host".

It may because the disconnect command is sent from the application so the gatt disconnection event will report immediately. But the disconnection complete event from the stack is not reported yet. So the app level will take the GATT_UNKNOWN as the disconnection reason.

I will report it to the FW team. For your application, as the disconnection command is sent from the app, the application will know when this happens. You can take it as local host terminated the connection.

pastedImage_0.png

thank you for your help!

0 Likes