mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component/bt : fix advertising data and refer bug
This commit is contained in:
parent
4079d1e008
commit
3b432735c6
@ -36,6 +36,10 @@ esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (adv_data->service_uuid_len & 0xf) { //not 16*n
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "btc_task.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gap_ble.h"
|
||||
#include "btc_gatt_util.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gap_ble_api.h"
|
||||
|
||||
@ -204,20 +205,18 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
|
||||
{
|
||||
tBT_UUID bt_uuid;
|
||||
|
||||
memcpy(&bt_uuid.uu, p_adv_data->p_service_uuid + position, LEN_UUID_128);
|
||||
bt_uuid.len = p_adv_data->service_uuid_len;
|
||||
btc128_to_bta_uuid(&bt_uuid, p_adv_data->p_service_uuid + position);
|
||||
|
||||
switch(bt_uuid.len)
|
||||
{
|
||||
case (LEN_UUID_16):
|
||||
{
|
||||
if (NULL == bta_adv_data->p_services)
|
||||
{
|
||||
bta_adv_data->p_services =
|
||||
GKI_getbuf(sizeof(tBTA_BLE_SERVICE));
|
||||
bta_adv_data->p_services = GKI_getbuf(sizeof(tBTA_BLE_SERVICE));
|
||||
bta_adv_data->p_services->list_cmpl = FALSE;
|
||||
bta_adv_data->p_services->num_service = 0;
|
||||
bta_adv_data->p_services->p_uuid =
|
||||
GKI_getbuf(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_16);
|
||||
bta_adv_data->p_services->p_uuid = GKI_getbuf(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_16);
|
||||
p_uuid_out16 = bta_adv_data->p_services->p_uuid;
|
||||
}
|
||||
|
||||
@ -246,7 +245,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
|
||||
|
||||
if (NULL != bta_adv_data->p_service_32b->p_uuid)
|
||||
{
|
||||
LOG_DEBUG("%s - In 32-UUID_data", __FUNCTION__);
|
||||
LOG_ERROR("%s - In 32-UUID_data", __FUNCTION__);
|
||||
mask |= BTM_BLE_AD_BIT_SERVICE_32;
|
||||
++bta_adv_data->p_service_32b->num_service;
|
||||
*p_uuid_out32++ = bt_uuid.uu.uuid32;
|
||||
@ -263,7 +262,7 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
|
||||
GKI_getbuf(sizeof(tBTA_BLE_128SERVICE));
|
||||
if (NULL != bta_adv_data->p_services_128b)
|
||||
{
|
||||
LOG_DEBUG("%s - In 128-UUID_data", __FUNCTION__);
|
||||
LOG_ERROR("%s - In 128-UUID_data", __FUNCTION__);
|
||||
mask |= BTM_BLE_AD_BIT_SERVICE_128;
|
||||
memcpy(bta_adv_data->p_services_128b->uuid128,
|
||||
bt_uuid.uu.uuid128, LEN_UUID_128);
|
||||
|
@ -40,6 +40,34 @@ int uuidType(unsigned char* p_uuid)
|
||||
return LEN_UUID_128;
|
||||
}
|
||||
|
||||
int btc128_to_bta_uuid(tBT_UUID *p_dest, uint8_t *p_src)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
p_dest->len = uuidType(p_src);
|
||||
|
||||
switch (p_dest->len)
|
||||
{
|
||||
case LEN_UUID_16:
|
||||
p_dest->uu.uuid16 = (p_src[13] << 8) + p_src[12];
|
||||
break;
|
||||
|
||||
case LEN_UUID_32:
|
||||
p_dest->uu.uuid32 = (p_src[13] << 8) + p_src[12];
|
||||
p_dest->uu.uuid32 += (p_src[15] << 24) + (p_src[14] << 16);
|
||||
break;
|
||||
|
||||
case LEN_UUID_128:
|
||||
for(i = 0; i != 16; ++i)
|
||||
p_dest->uu.uuid128[i] = p_src[i];
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* BTC -> BTA conversion functions
|
||||
*******************************************************************************/
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_gattc_api.h"
|
||||
|
||||
int btc128_to_bta_uuid(tBT_UUID *p_dest, uint8_t *p_src);
|
||||
void btc_to_bta_uuid(tBT_UUID *p_dest, esp_bt_uuid_t *p_src);
|
||||
void btc_to_bta_gatt_id(tBTA_GATT_ID *p_dest, esp_gatt_id_t *p_src);
|
||||
void btc_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, esp_gatt_srvc_id_t *p_src);
|
||||
|
@ -39,8 +39,12 @@
|
||||
|
||||
#define TEST_MANUFACTURER_DATA_LEN 17
|
||||
static uint16_t test_service_uuid = GATTS_SERVICE_UUID_TEST;
|
||||
static uint8_t test_service_uuid128[16] = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
static uint8_t test_service_uuid128[32] = {
|
||||
/* LSB <--------------------------------------------------------------------------------> MSB */
|
||||
//first uuid, 16bit, [12],[13] is the value
|
||||
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xAB, 0xCD, 0x00, 0x00,
|
||||
//second uuid, 32bit, [12], [13], [14], [15] is the value
|
||||
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xAB, 0xCD, 0xAB, 0xCD,};
|
||||
|
||||
static uint8_t test_manufacturer[TEST_MANUFACTURER_DATA_LEN] = {0x12, 0x23, 0x45, 0x56};
|
||||
static esp_ble_adv_data_t test_adv_data = {
|
||||
@ -49,14 +53,14 @@ static esp_ble_adv_data_t test_adv_data = {
|
||||
.include_txpower = true,
|
||||
.min_interval = 0x20,
|
||||
.max_interval = 0x40,
|
||||
.appearance = 0x0,
|
||||
.manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
|
||||
.p_manufacturer_data = NULL, // &test_manufacturer[0],
|
||||
.appearance = 0x00,
|
||||
.manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
|
||||
.p_manufacturer_data = NULL, //&test_manufacturer[0],
|
||||
.service_data_len = 0,
|
||||
.p_service_data = NULL,
|
||||
.service_uuid_len = 2,
|
||||
.service_uuid_len = 32,
|
||||
.p_service_uuid = test_service_uuid128,
|
||||
.flag = 0,
|
||||
.flag = 0x2,
|
||||
};
|
||||
|
||||
static esp_ble_adv_params_t test_adv_params = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user