Component/bt: fix no set rand add callback event

This commit is contained in:
zhiweijian 2018-03-26 11:40:14 +08:00
parent da27816314
commit aa236809ad
11 changed files with 90 additions and 39 deletions

View file

@ -4625,14 +4625,18 @@ void bta_dm_ble_disconnect (tBTA_DM_MSG *p_data)
*******************************************************************************/ *******************************************************************************/
void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data) void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data)
{ {
BOOLEAN set_flag = false; tBTM_STATUS status = BTM_SET_STATIC_RAND_ADDR_FAIL;
if (p_data->set_addr.addr_type != BLE_ADDR_RANDOM) { if (p_data->set_addr.addr_type != BLE_ADDR_RANDOM) {
APPL_TRACE_ERROR("Invalid random adress type = %d\n", p_data->set_addr.addr_type); APPL_TRACE_ERROR("Invalid random adress type = %d\n", p_data->set_addr.addr_type);
if(p_data->set_addr.p_set_rand_addr_cback) {
(*p_data->set_addr.p_set_rand_addr_cback)(status);
}
return; return;
} }
//send the setting random address to BTM layer //send the setting random address to BTM layer
if ((set_flag = BTM_BleSetRandAddress(p_data->set_addr.address) != TRUE)){ status = BTM_BleSetRandAddress(p_data->set_addr.address);
APPL_TRACE_ERROR("%s,set random address fail.", __func__); if(p_data->set_addr.p_set_rand_addr_cback) {
(*p_data->set_addr.p_set_rand_addr_cback)(status);
} }
} }

View file

@ -2284,12 +2284,12 @@ extern void BTA_DmBleStopAdvertising(void)
** Description This function set the random address for the APP ** Description This function set the random address for the APP
** **
** Parameters rand_addr: the random address whith should be setting ** Parameters rand_addr: the random address whith should be setting
** ** p_set_rand_addr_cback: complete callback
** Returns void ** Returns void
** **
** **
*******************************************************************************/ *******************************************************************************/
extern void BTA_DmSetRandAddress(BD_ADDR rand_addr) extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback)
{ {
tBTA_DM_APT_SET_DEV_ADDR *p_msg; tBTA_DM_APT_SET_DEV_ADDR *p_msg;
APPL_TRACE_API("set the random address "); APPL_TRACE_API("set the random address ");
@ -2298,6 +2298,7 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr)
memcpy(p_msg->address, rand_addr, BD_ADDR_LEN); memcpy(p_msg->address, rand_addr, BD_ADDR_LEN);
p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT; p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT;
p_msg->addr_type = BLE_ADDR_RANDOM; p_msg->addr_type = BLE_ADDR_RANDOM;
p_msg->p_set_rand_addr_cback = p_set_rand_addr_cback;
//start sent the msg to the bta system control moudle //start sent the msg to the bta system control moudle
bta_sys_sendmsg(p_msg); bta_sys_sendmsg(p_msg);
} }

View file

@ -409,6 +409,8 @@ typedef tBTM_ADD_WHITELIST_CBACK tBTA_ADD_WHITELIST_CBACK;
typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK; typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK;
typedef tBTM_SET_RAND_ADDR_CBACK tBTA_SET_RAND_ADDR_CBACK;
typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK; typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK;
typedef tBTM_CMPL_CB tBTA_CMPL_CB; typedef tBTM_CMPL_CB tBTA_CMPL_CB;
@ -2060,7 +2062,7 @@ extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration,
extern void BTA_DmBleStopAdvertising(void); extern void BTA_DmBleStopAdvertising(void);
extern void BTA_DmSetRandAddress(BD_ADDR rand_addr); extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback);
#endif #endif

View file

@ -532,6 +532,7 @@ typedef struct {
BT_HDR hdr; BT_HDR hdr;
tBLE_ADDR_TYPE addr_type; tBLE_ADDR_TYPE addr_type;
BD_ADDR address; BD_ADDR address;
tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback;
} tBTA_DM_APT_SET_DEV_ADDR; } tBTA_DM_APT_SET_DEV_ADDR;
/* set adv parameter for BLE advertising */ /* set adv parameter for BLE advertising */

View file

@ -115,6 +115,9 @@ static esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status)
case HCI_SUCCESS: case HCI_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS; esp_status = ESP_BT_STATUS_SUCCESS;
break; break;
case HCI_ERR_ESP_VENDOR_FAIL:
esp_status = ESP_BT_STATUS_FAIL;
break;
case HCI_ERR_HOST_TIMEOUT: case HCI_ERR_HOST_TIMEOUT:
esp_status = ESP_BT_STATUS_TIMEOUT; esp_status = ESP_BT_STATUS_TIMEOUT;
break; break;
@ -169,6 +172,12 @@ static esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status)
case BTM_SET_PRIVACY_FAIL: case BTM_SET_PRIVACY_FAIL:
esp_status = ESP_BT_STATUS_FAIL; esp_status = ESP_BT_STATUS_FAIL;
break; break;
case BTM_INVALID_STATIC_RAND_ADDR:
esp_status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
break;
case BTM_SET_STATIC_RAND_ADDR_FAIL:
esp_status = ESP_BT_STATUS_FAIL;
break;
default: default:
esp_status = ESP_BT_STATUS_FAIL; esp_status = ESP_BT_STATUS_FAIL;
break; break;
@ -714,6 +723,24 @@ static void btc_add_whitelist_complete_callback(UINT8 status, tBTM_WL_OPERATION
} }
} }
static void btc_set_rand_addr_callback(UINT8 status)
{
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
param.set_rand_addr_cmpl.status = btc_btm_status_to_esp_status(status); //todo status
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
static void btc_set_local_privacy_callback(UINT8 status) static void btc_set_local_privacy_callback(UINT8 status)
{ {
esp_ble_gap_cb_param_t param; esp_ble_gap_cb_param_t param;
@ -821,13 +848,8 @@ static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_len
BTA_DmBleSetDataLength(remote_device, tx_data_length, p_set_pkt_data_cback); BTA_DmBleSetDataLength(remote_device, tx_data_length, p_set_pkt_data_cback);
} }
static void btc_ble_set_rand_addr (BD_ADDR rand_addr) static void btc_ble_set_rand_addr (BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback)
{ {
esp_ble_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_SUCCESS;
if (rand_addr != NULL) { if (rand_addr != NULL) {
/* /*
A static address is a 48-bit randomly generated address and shall meet the following requirements: A static address is a 48-bit randomly generated address and shall meet the following requirements:
@ -842,25 +864,15 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
&& memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0 && memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0
&& memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){ && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){
BTA_DmSetRandAddress(rand_addr); BTA_DmSetRandAddress(rand_addr, btc_set_rand_addr_callback);
} else { } else {
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR; btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
LOG_ERROR("Invalid random address, the high bit should be 0b11, all bits of the random part shall not be to 1 or 0"); LOG_ERROR("Invalid random address, the high bit should be 0b11, all bits of the random part shall not be to 1 or 0");
} }
} else { } else {
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR; btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
LOG_ERROR("Invalid random addressm, the address value is NULL"); LOG_ERROR("Invalid random addressm, the address value is NULL");
} }
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_ble_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
} }
static void btc_ble_config_local_privacy(bool privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback) static void btc_ble_config_local_privacy(bool privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
@ -1057,7 +1069,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
case BTC_GAP_BLE_ACT_SET_RAND_ADDRESS: { case BTC_GAP_BLE_ACT_SET_RAND_ADDRESS: {
BD_ADDR bd_addr; BD_ADDR bd_addr;
memcpy(bd_addr, arg->set_rand_addr.rand_addr, sizeof(BD_ADDR)); memcpy(bd_addr, arg->set_rand_addr.rand_addr, sizeof(BD_ADDR));
btc_ble_set_rand_addr(bd_addr); btc_ble_set_rand_addr(bd_addr, btc_set_rand_addr_callback);
break; break;
} }
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY: case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:

View file

@ -1937,7 +1937,14 @@ void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len, BOOLEAN enhanced)
handle = HCID_GET_HANDLE (handle); handle = HCID_GET_HANDLE (handle);
btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match); btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match);
if(role == HCI_ROLE_SLAVE) {
//clear p_cb->state, controller will stop adv when ble connected.
tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
if(p_cb) {
p_cb->adv_mode = BTM_BLE_ADV_DISABLE;
p_cb->state = BTM_BLE_STOP_ADV;
}
}
l2cble_conn_comp (handle, role, bda, bda_type, conn_interval, l2cble_conn_comp (handle, role, bda, bda_type, conn_interval,
conn_latency, conn_timeout); conn_latency, conn_timeout);

View file

@ -756,10 +756,18 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK
if (p_cb->privacy_mode == BTM_PRIVACY_NONE if (p_cb->privacy_mode == BTM_PRIVACY_NONE
&& random_cb->own_addr_type == BLE_ADDR_RANDOM) { && random_cb->own_addr_type == BLE_ADDR_RANDOM) {
BTM_TRACE_ERROR("Have set random adress, can't set privacy "); BTM_TRACE_ERROR("Have set random adress, can't set privacy ");
if (random_cb && random_cb->set_local_privacy_cback){
(*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_FAIL);
random_cb->set_local_privacy_cback = NULL;
}
return FALSE; return FALSE;
} }
if (!(p_cb->inq_var.state != BTM_BLE_STOP_SCAN && p_cb->inq_var.state != BTM_BLE_STOP_ADV)) { if (!(p_cb->inq_var.state == BTM_BLE_STOP_SCAN || p_cb->inq_var.state == BTM_BLE_STOP_ADV || p_cb->inq_var.state == BTM_BLE_IDLE)) {
BTM_TRACE_ERROR("Advertising or scaning now, can't set privacy "); BTM_TRACE_ERROR("Advertising or scaning now, can't set privacy ");
if (random_cb && random_cb->set_local_privacy_cback){
(*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_FAIL);
random_cb->set_local_privacy_cback = NULL;
}
return FALSE; return FALSE;
} }
@ -1199,11 +1207,18 @@ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max,
*/ */
if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM && own_bda_type == BLE_ADDR_PUBLIC) { if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM && own_bda_type == BLE_ADDR_PUBLIC) {
BTM_TRACE_ERROR ("own_addr_type is BLE_ADDR_RANDOM but use BLE_ADDR_PUBLIC\n"); BTM_TRACE_ERROR ("own_addr_type is BLE_ADDR_RANDOM but use BLE_ADDR_PUBLIC\n");
if(adv_cb) {
(* adv_cb)(HCI_ERR_ESP_VENDOR_FAIL);
}
return BTM_ILLEGAL_VALUE; return BTM_ILLEGAL_VALUE;
} }
if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) ||
!BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) { !BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) {
BTM_TRACE_ERROR ("adv_int_min or adv_int_max is invalid\n");
if(adv_cb) {
(* adv_cb)(HCI_ERR_ESP_VENDOR_FAIL);
}
return BTM_ILLEGAL_VALUE; return BTM_ILLEGAL_VALUE;
} }
@ -1558,12 +1573,10 @@ tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len)
** Returns void ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
BOOLEAN BTM_BleSetRandAddress(BD_ADDR rand_addr) tBTM_STATUS BTM_BleSetRandAddress(BD_ADDR rand_addr)
{ {
BOOLEAN set_flag = false;
if (rand_addr == NULL) if (rand_addr == NULL)
return set_flag; return BTM_SET_STATIC_RAND_ADDR_FAIL;
/* /*
* Temporary solutions for pair with random address: * Temporary solutions for pair with random address:
@ -1573,19 +1586,22 @@ BOOLEAN BTM_BleSetRandAddress(BD_ADDR rand_addr)
#if BLE_PRIVACY_SPT == TRUE #if BLE_PRIVACY_SPT == TRUE
if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) { if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) {
BTM_TRACE_ERROR("privacy_mode is not BTM_PRIVACY_NONE "); BTM_TRACE_ERROR("privacy_mode is not BTM_PRIVACY_NONE ");
return set_flag; return BTM_SET_STATIC_RAND_ADDR_FAIL;
} }
#endif #endif
if (!(btm_cb.ble_ctr_cb.inq_var.state != BTM_BLE_STOP_SCAN && btm_cb.ble_ctr_cb.inq_var.state != BTM_BLE_STOP_ADV)) { if (!(btm_cb.ble_ctr_cb.inq_var.state == BTM_BLE_STOP_SCAN || btm_cb.ble_ctr_cb.inq_var.state == BTM_BLE_STOP_ADV || btm_cb.ble_ctr_cb.inq_var.state == BTM_BLE_IDLE)) {
BTM_TRACE_ERROR("Advertising or scaning now, can't set randaddress "); BTM_TRACE_ERROR("Advertising or scaning now, can't set randaddress %d", btm_cb.ble_ctr_cb.inq_var.state);
return FALSE; return BTM_SET_STATIC_RAND_ADDR_FAIL;
} }
memcpy(btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, rand_addr, BD_ADDR_LEN); memcpy(btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, rand_addr, BD_ADDR_LEN);
btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM; btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM;
//send the set random address to the controller //send the set random address to the controller
set_flag = btsnd_hcic_ble_set_random_addr(rand_addr); if(btsnd_hcic_ble_set_random_addr(rand_addr)) {
return set_flag; return BTM_SUCCESS;
} else {
return BTM_SET_STATIC_RAND_ADDR_FAIL;
}
} }
/******************************************************************************* /*******************************************************************************

View file

@ -72,6 +72,8 @@ enum {
BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* 22 controller setting data length is unsupported*/ BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* 22 controller setting data length is unsupported*/
BTM_SET_PRIVACY_SUCCESS, /* 23 enable/disable local privacy success */ BTM_SET_PRIVACY_SUCCESS, /* 23 enable/disable local privacy success */
BTM_SET_PRIVACY_FAIL, /* 24 enable/disable local privacy failed*/ BTM_SET_PRIVACY_FAIL, /* 24 enable/disable local privacy failed*/
BTM_SET_STATIC_RAND_ADDR_FAIL, /* 25 Command failed */
BTM_INVALID_STATIC_RAND_ADDR, /* 26 invalid static rand addr */
}; };
typedef uint8_t tBTM_STATUS; typedef uint8_t tBTM_STATUS;
@ -182,6 +184,8 @@ typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM
typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params); typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params);
typedef void (tBTM_SET_RAND_ADDR_CBACK) (UINT8 status);
typedef void (tBTM_ADD_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_opration); typedef void (tBTM_ADD_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_opration);
typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status); typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status);

View file

@ -982,7 +982,7 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask,
tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len); tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len);
BOOLEAN BTM_BleSetRandAddress(BD_ADDR rand_addr); tBTM_STATUS BTM_BleSetRandAddress(BD_ADDR rand_addr);
/******************************************************************************* /*******************************************************************************

View file

@ -104,6 +104,7 @@ typedef UINT8 tBTM_BLE_SEC_REQ_ACT;
#define BTM_VSC_CHIP_CAPABILITY_M_VERSION 95 #define BTM_VSC_CHIP_CAPABILITY_M_VERSION 95
typedef enum { typedef enum {
BTM_BLE_IDLE,
BTM_BLE_SCANNING, BTM_BLE_SCANNING,
BTM_BLE_SCAN_PENDING, BTM_BLE_SCAN_PENDING,
BTM_BLE_STOP_SCAN, BTM_BLE_STOP_SCAN,

View file

@ -792,6 +792,9 @@
#define HCI_ERR_MAX_ERR 0x43 #define HCI_ERR_MAX_ERR 0x43
//ESP vendor error code
#define HCI_ERR_ESP_VENDOR_FAIL 0xE0
#define HCI_HINT_TO_RECREATE_AMP_PHYS_LINK 0xFF #define HCI_HINT_TO_RECREATE_AMP_PHYS_LINK 0xFF
/* /*