MediaTek-Labs / Arduino-Add-On-for-LinkIt-SDK

Arduino board support package for LinkIt 7697
https://docs.labs.mediatek.com/resource/linkit7697-arduino/en
34 stars 33 forks source link

LBLEClient cannot connect to specific BLE peripheral #102

Closed pablosun closed 6 years ago

pablosun commented 6 years ago

Reproduce Steps

  1. Use LBLEClient to connect to a 3rd party BLE peripheral

Error & Expected Results

Cannot connect. However, the 3rd party BLE peripheral device can be connected by smart phones.

Log file: mabeee_device.txt

Environment

pablosun commented 6 years ago

It looks like that the connection is terminated by peripheral device immediately after connection.

[T: 28417 M: common C: info F: operator() L: 500]: ARD:bt_gap_le_connect() recieves BT_GAP_LE_CONNECT_IND
[T: 28438 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_evt_proc
[T: 28447 M: BT C: info F: bt_debug_log L: 112]: [I][GAP] bt_gap_le_connection_update_proc: timer_id(0x0c002013)
[T: 28462 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 28476 M: BT C: info F: bt_debug_log L: 112]: [I][ATT] bt_att_send_packet
[T: 28485 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_acl_le_send
[T: 28563 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_evt_proc
[T: 28563 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_timer_cancel_and_callback status: 0x04000002
[T: 28563 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 28647 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_evt_proc
[T: 28647 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_timer_cancel_and_callback status: 0x04000002
[T: 28647 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 28731 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_acl_proc
[T: 28731 M: BT C: info F: bt_debug_log L: 112]: [I][ATT] bt_att_send_packet
[T: 28731 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_acl_le_send
[T: 28731 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] LE acl Rx proc finished

[T: 28731 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 28814 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_evt_proc
[T: 28814 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_timer_cancel_and_callback status: 0x04000002
[T: 28814 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 28898 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_acl_proc
[T: 28898 M: BT C: info F: bt_debug_log L: 112]: [I][ATT] bt_att_send_packet
[T: 28898 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_acl_le_send
[T: 28898 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] LE acl Rx proc finished

[T: 28898 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 28991 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_evt_proc
[T: 28991 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_timer_cancel_and_callback status: 0x04000002
[T: 28991 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 28991 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_evt_proc
[T: 28991 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_timer_cancel_and_callback status: 0x04000002
[T: 28991 M: BT C: info F: bt_debug_log L: 112]: [I][GAP] bt_gap_le_connection_update_proc: timer_id(0x0c01033e)
[T: 28991 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] Rx proc: status(0x00000000)
[T: 29035 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_hci_evt_proc
[T: 29035 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] bt_timer_cancel_and_callback status: 0x04000002
[T: 29035 M: BT C: info F: bt_debug_log L: 112]: [I][GAP] bt_gap_le_event_callback: timer_id(0x0c010005)
[T: 29035 M: BT C: info F: bt_debug_log L: 112]: [I][GAP] BT_HCI_EVT_DISCONNECTION_COMPLETE: handle(0x0200)
[T: 29035 M: BTHCI C: info F: bt_debug_log L: 107]: [I][HCI] connection destroy, acl_credit_counter:8
[T: 29035 M: common C: info F: onEvent L: 612]: ARD:Disconnected with status = 0x0, reason = 0x3b
[T: 29035 M: BT C: info F: bt_debug_log L: 112]: [I][GAP] LE Connection Disconnected: handle(0x0200)

The Reason in BT_HCI_EVT_DISCONNECTION_COMPLETE is 0x3B, which is defined in bt_hci.h:

#define BT_HCI_STATUS_UNACCEPTABLE_CONNECTION_PARAMETERS     0x3B   /**< Unacceptable connection parameters. */
pablosun commented 6 years ago

This may be related to the desired connection interval. We may try change the connection interval setting in LBLECentral.cpp to maximum value:

bool LBLEClient::connect(const LBLEAddress& address)
{
    bt_hci_cmd_le_create_connection_t conn_para;
    conn_para.le_scan_interval = 0x0010;
    conn_para.le_scan_window = 0x0010;
    conn_para.initiator_filter_policy = BT_HCI_CONN_FILTER_ASSIGNED_ADDRESS;
    conn_para.own_address_type = BT_ADDR_RANDOM;
    conn_para.conn_interval_min = 0x0006;
    conn_para.conn_interval_max = 0x0080;
    conn_para.conn_latency = 0x0000;
    conn_para.supervision_timeout = 0x07d0;
    conn_para.minimum_ce_length = 0x0000;
    conn_para.maximum_ce_length = 0x0050;
...

and change the line

conn_para.conn_interval_max = 0x0080;

to

conn_para.conn_interval_max = 0x0190;
pablosun commented 6 years ago

We need to define bt_gap_le_is_connection_update_request_accepted to prevent remote peripheral from disconnecting.