future_t **future_p;
if (esp_already_enable) {
- LOG_ERROR("%s already enable\n");
+ LOG_ERROR("%s already enable\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
future_t **future_p;
if (!esp_already_enable) {
- LOG_ERROR("%s already disable\n");
+ LOG_ERROR("%s already disable\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
future_t **future_p;
if (esp_already_init) {
- LOG_ERROR("%s already init\n");
+ LOG_ERROR("%s already init\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
future_t **future_p;
if (!esp_already_init) {
- LOG_ERROR("%s already deinit\n");
+ LOG_ERROR("%s already deinit\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
- LOG_ERROR("%s failed\n");
+ LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
- uint16_t app_uuid;
if (app_id < APP_ID_MIN || app_id > APP_ID_MAX)
return ESP_ERR_INVALID_ARG;
uint32_t uuid32;
uint8_t uuid128[ESP_UUID_LEN_128];
} uuid;
-}esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
+} __attribute__((packed)) esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
typedef enum {
ESP_BT_DEVICE_TYPE_BREDR = 0x01,
typedef struct {
esp_bt_uuid_t uuid;
uint8_t inst_id;
-} esp_gatt_id_t;
+} __attribute__((packed)) esp_gatt_id_t;
typedef struct {
esp_gatt_id_t id;
- uint8_t is_primary;
-} esp_gatt_srvc_id_t;
+ bool is_primary;
+} __attribute__((packed)) esp_gatt_srvc_id_t;
typedef enum {
AUTH_REQ_NO_SCATTERNET, /* Device doesn't support scatternet, it might
return BT_STATUS_PARM_INVALID;
}
- LOG_DEBUG("%s msg %u %u %u %08x\n", __func__, msg->sig, msg->pid, msg->act, msg->arg);
+ LOG_DEBUG("%s msg %u %u %u %p\n", __func__, msg->sig, msg->pid, msg->act, arg);
memcpy(&lmsg, msg, sizeof(btc_msg_t));
if (arg) {
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_DATA, ¶m);
break;
default:
- LOG_ERROR("%s UNKNOWN %d\n", msg->act);
+ LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act);
break;
}
}
}
break;
default:
- LOG_ERROR("%s UNKNOWN %d\n", msg->act);
+ LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act);
break;
}
}
}
if (p_adv_data->include_name) {
- LOG_ERROR("include dev name\n");
mask |= BTM_BLE_AD_BIT_DEV_NAME;
}
- if (p_adv_data->include_txpower)
+ if (p_adv_data->include_txpower) {
mask |= BTM_BLE_AD_BIT_TX_PWR;
+ }
if (p_adv_data->min_interval > 0 && p_adv_data->max_interval > 0 &&
p_adv_data->max_interval >= p_adv_data->min_interval)
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;
-
+ bt_uuid.len = p_adv_data->service_uuid_len;
switch(bt_uuid.len)
{
case (LEN_UUID_16):
if (NULL != bta_adv_data->p_service_32b->p_uuid)
{
- LOG_ERROR("%s - In 32-UUID_data", __FUNCTION__);
+ LOG_DEBUG("%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;
GKI_getbuf(sizeof(tBTA_BLE_128SERVICE));
if (NULL != bta_adv_data->p_services_128b)
{
- LOG_ERROR("%s - In 128-UUID_data", __FUNCTION__);
+ LOG_DEBUG("%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);
- LOG_ERROR("%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x", bt_uuid.uu.uuid128[0],
+ LOG_DEBUG("%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x", bt_uuid.uu.uuid128[0],
bt_uuid.uu.uuid128[1],bt_uuid.uu.uuid128[2], bt_uuid.uu.uuid128[3],
bt_uuid.uu.uuid128[4],bt_uuid.uu.uuid128[5],bt_uuid.uu.uuid128[6],
bt_uuid.uu.uuid128[7],bt_uuid.uu.uuid128[8],bt_uuid.uu.uuid128[9],
tBTA_BLE_AD_MASK data_mask = 0;
btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask);
+
if (!adv_data->set_scan_rsp){
BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback);
}else{
LOG_ERROR("Invalid advertisting type parameters.\n");
return;
}
- LOG_ERROR("API_Ble_AppStartAdvertising\n");
+ LOG_DEBUG("API_Ble_AppStartAdvertising\n");
///
memcpy(peer_addr.bda, ble_adv_params->peer_addr, ESP_BD_ADDR_LEN);
switch (msg->act)
{
case BTC_GAP_BLE_ACT_CFG_ADV_DATA: {
- esp_ble_adv_data_t *src = (esp_ble_adv_data_t *)p_src;
- esp_ble_adv_data_t *dst = (esp_ble_adv_data_t*) p_dest;
+ btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src;
+ btc_ble_gap_args_t *dst = (btc_ble_gap_args_t*) p_dest;
- if (src->p_manufacturer_data) {
- dst->p_manufacturer_data = GKI_getbuf(src->manufacturer_len);
- memcpy(dst->p_manufacturer_data, src->p_manufacturer_data,
- src->manufacturer_len);
+ if (src->adv_data.p_manufacturer_data) {
+ dst->adv_data.p_manufacturer_data = GKI_getbuf(src->adv_data.manufacturer_len);
+ memcpy(dst->adv_data.p_manufacturer_data, src->adv_data.p_manufacturer_data,
+ src->adv_data.manufacturer_len);
}
- if (src->p_service_data) {
- dst->p_service_data = GKI_getbuf(src->service_data_len);
- memcpy(dst->p_service_data, src->p_service_data, src->service_data_len);
+ if (src->adv_data.p_service_data) {
+ dst->adv_data.p_service_data = GKI_getbuf(src->adv_data.service_data_len);
+ memcpy(dst->adv_data.p_service_data, src->adv_data.p_service_data, src->adv_data.service_data_len);
}
- if (src->p_service_uuid) {
- dst->p_service_uuid = GKI_getbuf(src->service_uuid_len);
- memcpy(dst->p_service_uuid, src->p_service_uuid, src->service_uuid_len);
+ if (src->adv_data.p_service_uuid) {
+ dst->adv_data.p_service_uuid = GKI_getbuf(src->adv_data.service_uuid_len);
+ memcpy(dst->adv_data.p_service_uuid, src->adv_data.p_service_uuid, src->adv_data.service_uuid_len);
}
break;
}
default:
- LOG_ERROR("Unhandled deep copy\n", msg->act);
+ LOG_ERROR("Unhandled deep copy %d\n", msg->act);
break;
}
}
static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
{
+ LOG_DEBUG("%s \n", __func__);
switch (msg->act) {
case BTC_GAP_BLE_ACT_CFG_ADV_DATA: {
- esp_ble_adv_data_t *adv = (esp_ble_adv_data_t *)msg->arg;
+ esp_ble_adv_data_t *adv = &((btc_ble_gap_args_t *)msg->arg)->adv_data;
if (adv->p_service_data)
GKI_freebuf(adv->p_service_data);
break;
}
default:
- LOG_ERROR("Unhandled deep free\n", msg->act);
+ LOG_DEBUG("Unhandled deep free %d\n", msg->act);
break;
}
}
{
btc_ble_gap_args_t *arg = (btc_ble_gap_args_t *)msg->arg;
- LOG_ERROR("%s act %d\n", __FUNCTION__, msg->act);
+ LOG_DEBUG("%s act %d\n", __FUNCTION__, msg->act);
switch (msg->act) {
case BTC_GAP_BLE_ACT_CFG_ADV_DATA:
return LEN_UUID_128;
}
-void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
-{
- char *p_byte = (char*)p_src;
- int i = 0;
-
- p_dest->len = uuidType(p_src->uu);
-
- switch (p_dest->len)
- {
- case LEN_UUID_16:
- p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
- break;
-
- case LEN_UUID_32:
- p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12];
- p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16);
- break;
-
- case LEN_UUID_128:
- for(i = 0; i != 16; ++i)
- p_dest->uu.uuid128[i] = p_byte[i];
- break;
-
- default:
- LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len);
- break;
- }
-}
-
-
/*******************************************************************************
* BTC -> BTA conversion functions
*******************************************************************************/
void btc_to_bta_uuid(tBT_UUID *p_dest, esp_bt_uuid_t *p_src)
{
- memcpy(p_dest, p_src, sizeof(esp_bt_uuid_t));
+ p_dest->len = p_src->len;
+ if (p_src->len == LEN_UUID_16) {
+ p_dest->uu.uuid16 = p_src->uuid.uuid16;
+ } else if (p_src->len == LEN_UUID_32) {
+ p_dest->uu.uuid32 = p_src->uuid.uuid32;
+ } else if (p_src->len == LEN_UUID_128) {
+ memcpy(&p_dest->uu.uuid128, p_src->uuid.uuid128, p_dest->len);
+ } else {
+ LOG_ERROR("%s UUID len is invalid %d\n", __func__, p_dest->len);
+ }
}
-void btc_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, esp_gatt_srvc_id_t *p_src)
+void btc_to_bta_gatt_id(tBTA_GATT_ID *p_dest, esp_gatt_id_t *p_src)
{
- memcpy(p_dest, p_src, sizeof(esp_gatt_srvc_id_t));
+ p_dest->inst_id = p_src->inst_id;
+ btc_to_bta_uuid(&p_dest->uuid, &p_src->uuid);
}
-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)
{
- memcpy(p_dest, p_src, sizeof(esp_gatt_id_t));
+ p_dest->is_primary = p_src->is_primary;
+ btc_to_bta_gatt_id(&p_dest->id, &p_src->id);
}
+
/*******************************************************************************
* BTA -> BTC conversion functions
*******************************************************************************/
void bta_to_btc_uuid(esp_bt_uuid_t *p_dest, tBT_UUID *p_src)
{
- memcpy(p_dest, p_src, sizeof(esp_bt_uuid_t));
+ p_dest->len = p_src->len;
+ if (p_src->len == LEN_UUID_16) {
+ p_dest->uuid.uuid16 = p_src->uu.uuid16;
+ } else if (p_src->len == LEN_UUID_32) {
+ p_dest->uuid.uuid32 = p_src->uu.uuid32;
+ } else if (p_src->len == LEN_UUID_128) {
+ memcpy(&p_dest->uuid.uuid128, p_src->uu.uuid128, p_dest->len);
+ } else {
+ LOG_ERROR("%s UUID len is invalid %d\n", __func__, p_dest->len);
+ }
}
void bta_to_btc_gatt_id(esp_gatt_id_t *p_dest, tBTA_GATT_ID *p_src)
{
- memcpy(p_dest, p_src, sizeof(esp_gatt_id_t));
+ p_dest->inst_id = p_src->inst_id;
+ bta_to_btc_uuid(&p_dest->uuid, &p_src->uuid);
}
void bta_to_btc_srvc_id(esp_gatt_srvc_id_t *p_dest, tBTA_GATT_SRVC_ID *p_src)
{
- memcpy(p_dest, p_src, sizeof(esp_gatt_srvc_id_t));
+ p_dest->is_primary = p_src->is_primary;
+ bta_to_btc_gatt_id(&p_dest->id, &p_src->id);
}
void btc_to_bta_response(tBTA_GATTS_RSP *rsp_struct, esp_gatt_rsp_t *p_rsp)
param.create.service_id.is_primary = p_data->create.is_primary;
param.create.service_id.id.inst_id = p_data->create.svc_instance;
memcpy(¶m.create.service_id.id.uuid, &p_data->create.uuid, sizeof(esp_bt_uuid_t));
-
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, ¶m);
break;
case BTA_GATTS_ADD_INCL_SRVC_EVT:
return;
}
if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) {
- LOG_ERROR("%d Unknown HCI message type. Dropping this byte 0x%x,"
+ LOG_ERROR("%s Unknown HCI message type. Dropping this byte 0x%x,"
" min %x, max %x", __func__, type,
DATA_TYPE_ACL, DATA_TYPE_EVENT);
hci_hal_env.allocator->free(packet);
}
hdr_size = preamble_sizes[type - 1];
if (packet->len < hdr_size) {
- LOG_ERROR("Wrong packet length type=%s pkt_len=%d hdr_len=%d",
+ LOG_ERROR("Wrong packet length type=%d pkt_len=%d hdr_len=%d",
type, packet->len, hdr_size);
hci_hal_env.allocator->free(packet);
return;
#include "esp_bt_main.h"
#include "esp_bt_main.h"
-#define GATTS_SERVICE_UUID_TEST 0xFFFF
+#define GATTS_SERVICE_UUID_TEST 0x00FF
#define GATTS_CHAR_UUID_TEST 0xFF01
#define GATTS_DESCR_UUID_TEST 0x3333
#define APP_ID_TEST 0x18
#define GATTS_NUM_HANDLE_TEST 4
-#define TEST_DEVICE_NAME "snakeNB"
+#define TEST_DEVICE_NAME "ESP_GATTS_DEMO"
-#define TEST_MANUFACTURER_DATA_LEN 8
-static uint16_t test_service_uuid = GATTS_NUM_HANDLE_TEST;
-static uint8_t test_manufacturer[TEST_MANUFACTURER_DATA_LEN] = {0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1, 0x2};
+#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_manufacturer[TEST_MANUFACTURER_DATA_LEN] = {0x12, 0x23, 0x45, 0x56};
static esp_ble_adv_data_t test_adv_data = {
.set_scan_rsp = false,
.include_name = true,
.include_txpower = true,
.min_interval = 0x20,
.max_interval = 0x40,
- .appearance = 0,
- .manufacturer_len = TEST_MANUFACTURER_DATA_LEN,
- .p_manufacturer_data = &test_manufacturer[0],
+ .appearance = 0x0,
+ .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,
- .p_service_uuid = (uint8_t *)&test_service_uuid,
+ .p_service_uuid = test_service_uuid128,
+ .flag = 0,
};
static esp_ble_adv_params_t test_adv_params = {
static void gap_event_handler(uint32_t event, void *param)
{
LOG_ERROR("GAP_EVT, event %d\n", event);
+
+ switch (event) {
+ case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
+ esp_ble_gap_start_advertising(&test_adv_params);
+ break;
+ default:
+ break;
+ }
}
static void gatts_event_handler(uint32_t event, void *param)
case ESP_GATTS_REG_EVT:
LOG_ERROR("REGISTER_APP_EVT, status %d, gatt_if %d, app_id %d\n", p->reg.status, p->reg.gatt_if, p->reg.app_id);
gl_test.gatt_if = p->reg.gatt_if;
- gl_test.service_id.is_primary = 1;
+ gl_test.service_id.is_primary = true;
gl_test.service_id.id.inst_id = 0x00;
gl_test.service_id.id.uuid.len = ESP_UUID_LEN_16;
gl_test.service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST;
- esp_ble_gatts_create_service(gl_test.gatt_if, &gl_test.service_id, GATTS_NUM_HANDLE_TEST);
esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
esp_ble_gap_config_adv_data(&test_adv_data);
- esp_ble_gap_start_advertising(&test_adv_params);
+
+ esp_ble_gatts_create_service(gl_test.gatt_if, &gl_test.service_id, GATTS_NUM_HANDLE_TEST);
break;
case ESP_GATTS_READ_EVT: {
LOG_ERROR("GATT_READ_EVT, conn_id %d, trans_id %d, handle %d\n", p->read.conn_id, p->read.trans_id, p->read.handle);
esp_ble_gatts_register_callback(gatts_event_handler);
esp_ble_gap_register_callback(gap_event_handler);
- esp_ble_gatts_app_register(0x18);
+ esp_ble_gatts_app_register(GATTS_SERVICE_UUID_TEST);
+ //esp_ble_gatts_app_register(0x18);
return;
}