component/bt : gatts fix

1. gatt server demo
2. gatt server fix bug(bta btc covert bug)
3. fix print lost
This commit is contained in:
Tian Hao 2016-11-18 22:10:35 +08:00
parent 37365cef95
commit 0245a2028c
11 changed files with 104 additions and 100 deletions

View File

@ -27,14 +27,14 @@ esp_err_t esp_enable_bluetooth(void)
future_t **future_p; future_t **future_p;
if (esp_already_enable) { if (esp_already_enable) {
LOG_ERROR("%s already enable\n"); LOG_ERROR("%s already enable\n", __func__);
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
future_p = btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE); future_p = btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE);
*future_p = future_new(); *future_p = future_new();
if (*future_p == NULL) { if (*future_p == NULL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;
} }
@ -44,7 +44,7 @@ esp_err_t esp_enable_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL); btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) { if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL; return ESP_FAIL;
} }
@ -59,14 +59,14 @@ esp_err_t esp_disable_bluetooth(void)
future_t **future_p; future_t **future_p;
if (!esp_already_enable) { if (!esp_already_enable) {
LOG_ERROR("%s already disable\n"); LOG_ERROR("%s already disable\n", __func__);
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
future_p = btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE); future_p = btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE);
*future_p = future_new(); *future_p = future_new();
if (*future_p == NULL) { if (*future_p == NULL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;
} }
@ -76,7 +76,7 @@ esp_err_t esp_disable_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL); btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) { if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL; return ESP_FAIL;
} }
@ -91,14 +91,14 @@ esp_err_t esp_init_bluetooth(void)
future_t **future_p; future_t **future_p;
if (esp_already_init) { if (esp_already_init) {
LOG_ERROR("%s already init\n"); LOG_ERROR("%s already init\n", __func__);
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE); future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE);
*future_p = future_new(); *future_p = future_new();
if (*future_p == NULL) { if (*future_p == NULL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;
} }
@ -110,7 +110,7 @@ esp_err_t esp_init_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL); btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) { if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL; return ESP_FAIL;
} }
@ -126,14 +126,14 @@ esp_err_t esp_deinit_bluetooth(void)
future_t **future_p; future_t **future_p;
if (!esp_already_init) { if (!esp_already_init) {
LOG_ERROR("%s already deinit\n"); LOG_ERROR("%s already deinit\n", __func__);
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
future_p = btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE); future_p = btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE);
*future_p = future_new(); *future_p = future_new();
if (*future_p == NULL) { if (*future_p == NULL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;
} }
@ -143,7 +143,7 @@ esp_err_t esp_deinit_bluetooth(void)
btc_transfer_context(&msg, NULL, 0, NULL); btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) { if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n"); LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL; return ESP_FAIL;
} }

View File

@ -29,7 +29,6 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
{ {
btc_msg_t msg; btc_msg_t msg;
btc_ble_gatts_args_t arg; btc_ble_gatts_args_t arg;
uint16_t app_uuid;
if (app_id < APP_ID_MIN || app_id > APP_ID_MAX) if (app_id < APP_ID_MIN || app_id > APP_ID_MAX)
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;

View File

@ -30,7 +30,7 @@ typedef struct {
uint32_t uuid32; uint32_t uuid32;
uint8_t uuid128[ESP_UUID_LEN_128]; uint8_t uuid128[ESP_UUID_LEN_128];
} uuid; } 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 { typedef enum {
ESP_BT_DEVICE_TYPE_BREDR = 0x01, ESP_BT_DEVICE_TYPE_BREDR = 0x01,

View File

@ -70,12 +70,12 @@ typedef enum {
typedef struct { typedef struct {
esp_bt_uuid_t uuid; esp_bt_uuid_t uuid;
uint8_t inst_id; uint8_t inst_id;
} esp_gatt_id_t; } __attribute__((packed)) esp_gatt_id_t;
typedef struct { typedef struct {
esp_gatt_id_t id; esp_gatt_id_t id;
uint8_t is_primary; bool is_primary;
} esp_gatt_srvc_id_t; } __attribute__((packed)) esp_gatt_srvc_id_t;
typedef enum { typedef enum {
AUTH_REQ_NO_SCATTERNET, /* Device doesn't support scatternet, it might AUTH_REQ_NO_SCATTERNET, /* Device doesn't support scatternet, it might

View File

@ -94,7 +94,7 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
return BT_STATUS_PARM_INVALID; 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)); memcpy(&lmsg, msg, sizeof(btc_msg_t));
if (arg) { if (arg) {

View File

@ -357,7 +357,7 @@ void btc_blufi_cb_handler(btc_msg_t *msg)
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_DATA, &param); BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_DATA, &param);
break; break;
default: default:
LOG_ERROR("%s UNKNOWN %d\n", msg->act); LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act);
break; break;
} }
} }
@ -381,7 +381,7 @@ void btc_blufi_call_handler(btc_msg_t *msg)
} }
break; break;
default: default:
LOG_ERROR("%s UNKNOWN %d\n", msg->act); LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act);
break; break;
} }
} }

View File

@ -116,12 +116,12 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
} }
if (p_adv_data->include_name) { if (p_adv_data->include_name) {
LOG_ERROR("include dev name\n");
mask |= BTM_BLE_AD_BIT_DEV_NAME; 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; mask |= BTM_BLE_AD_BIT_TX_PWR;
}
if (p_adv_data->min_interval > 0 && p_adv_data->max_interval > 0 && if (p_adv_data->min_interval > 0 && p_adv_data->max_interval > 0 &&
p_adv_data->max_interval >= p_adv_data->min_interval) p_adv_data->max_interval >= p_adv_data->min_interval)
@ -205,7 +205,6 @@ static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DAT
memcpy(&bt_uuid.uu, p_adv_data->p_service_uuid + position, LEN_UUID_128); 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) switch(bt_uuid.len)
{ {
case (LEN_UUID_16): case (LEN_UUID_16):
@ -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) 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; mask |= BTM_BLE_AD_BIT_SERVICE_32;
++bta_adv_data->p_service_32b->num_service; ++bta_adv_data->p_service_32b->num_service;
*p_uuid_out32++ = bt_uuid.uu.uuid32; *p_uuid_out32++ = bt_uuid.uu.uuid32;
@ -263,11 +262,11 @@ 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)); GKI_getbuf(sizeof(tBTA_BLE_128SERVICE));
if (NULL != bta_adv_data->p_services_128b) 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; mask |= BTM_BLE_AD_BIT_SERVICE_128;
memcpy(bta_adv_data->p_services_128b->uuid128, memcpy(bta_adv_data->p_services_128b->uuid128,
bt_uuid.uu.uuid128, LEN_UUID_128); 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[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[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], bt_uuid.uu.uuid128[7],bt_uuid.uu.uuid128[8],bt_uuid.uu.uuid128[9],
@ -353,6 +352,7 @@ static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data,
tBTA_BLE_AD_MASK data_mask = 0; tBTA_BLE_AD_MASK data_mask = 0;
btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask); btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask);
if (!adv_data->set_scan_rsp){ if (!adv_data->set_scan_rsp){
BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback); BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback);
}else{ }else{
@ -415,7 +415,7 @@ void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params)
LOG_ERROR("Invalid advertisting type parameters.\n"); LOG_ERROR("Invalid advertisting type parameters.\n");
return; 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); memcpy(peer_addr.bda, ble_adv_params->peer_addr, ESP_BD_ADDR_LEN);
@ -592,37 +592,38 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
switch (msg->act) switch (msg->act)
{ {
case BTC_GAP_BLE_ACT_CFG_ADV_DATA: { case BTC_GAP_BLE_ACT_CFG_ADV_DATA: {
esp_ble_adv_data_t *src = (esp_ble_adv_data_t *)p_src; btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src;
esp_ble_adv_data_t *dst = (esp_ble_adv_data_t*) p_dest; btc_ble_gap_args_t *dst = (btc_ble_gap_args_t*) p_dest;
if (src->p_manufacturer_data) { if (src->adv_data.p_manufacturer_data) {
dst->p_manufacturer_data = GKI_getbuf(src->manufacturer_len); dst->adv_data.p_manufacturer_data = GKI_getbuf(src->adv_data.manufacturer_len);
memcpy(dst->p_manufacturer_data, src->p_manufacturer_data, memcpy(dst->adv_data.p_manufacturer_data, src->adv_data.p_manufacturer_data,
src->manufacturer_len); src->adv_data.manufacturer_len);
} }
if (src->p_service_data) { if (src->adv_data.p_service_data) {
dst->p_service_data = GKI_getbuf(src->service_data_len); dst->adv_data.p_service_data = GKI_getbuf(src->adv_data.service_data_len);
memcpy(dst->p_service_data, src->p_service_data, src->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) { if (src->adv_data.p_service_uuid) {
dst->p_service_uuid = GKI_getbuf(src->service_uuid_len); dst->adv_data.p_service_uuid = GKI_getbuf(src->adv_data.service_uuid_len);
memcpy(dst->p_service_uuid, src->p_service_uuid, src->service_uuid_len); memcpy(dst->adv_data.p_service_uuid, src->adv_data.p_service_uuid, src->adv_data.service_uuid_len);
} }
break; break;
} }
default: default:
LOG_ERROR("Unhandled deep copy\n", msg->act); LOG_ERROR("Unhandled deep copy %d\n", msg->act);
break; break;
} }
} }
static void btc_gap_ble_arg_deep_free(btc_msg_t *msg) static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
{ {
LOG_DEBUG("%s \n", __func__);
switch (msg->act) { switch (msg->act) {
case BTC_GAP_BLE_ACT_CFG_ADV_DATA: { 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) if (adv->p_service_data)
GKI_freebuf(adv->p_service_data); GKI_freebuf(adv->p_service_data);
@ -634,7 +635,7 @@ static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
break; break;
} }
default: default:
LOG_ERROR("Unhandled deep free\n", msg->act); LOG_DEBUG("Unhandled deep free %d\n", msg->act);
break; break;
} }
} }
@ -643,7 +644,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
{ {
btc_ble_gap_args_t *arg = (btc_ble_gap_args_t *)msg->arg; 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) { switch (msg->act) {
case BTC_GAP_BLE_ACT_CFG_ADV_DATA: case BTC_GAP_BLE_ACT_CFG_ADV_DATA:

View File

@ -40,71 +40,64 @@ int uuidType(unsigned char* p_uuid)
return LEN_UUID_128; 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 * BTC -> BTA conversion functions
*******************************************************************************/ *******************************************************************************/
void btc_to_bta_uuid(tBT_UUID *p_dest, esp_bt_uuid_t *p_src) 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)
{
memcpy(p_dest, p_src, sizeof(esp_gatt_srvc_id_t));
} }
void btc_to_bta_gatt_id(tBTA_GATT_ID *p_dest, esp_gatt_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_id_t)); p_dest->inst_id = p_src->inst_id;
btc_to_bta_uuid(&p_dest->uuid, &p_src->uuid);
} }
void btc_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, esp_gatt_srvc_id_t *p_src)
{
p_dest->is_primary = p_src->is_primary;
btc_to_bta_gatt_id(&p_dest->id, &p_src->id);
}
/******************************************************************************* /*******************************************************************************
* BTA -> BTC conversion functions * BTA -> BTC conversion functions
*******************************************************************************/ *******************************************************************************/
void bta_to_btc_uuid(esp_bt_uuid_t *p_dest, tBT_UUID *p_src) 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) 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) 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) void btc_to_bta_response(tBTA_GATTS_RSP *rsp_struct, esp_gatt_rsp_t *p_rsp)

View File

@ -286,7 +286,6 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.create.service_id.is_primary = p_data->create.is_primary; param.create.service_id.is_primary = p_data->create.is_primary;
param.create.service_id.id.inst_id = p_data->create.svc_instance; param.create.service_id.id.inst_id = p_data->create.svc_instance;
memcpy(&param.create.service_id.id.uuid, &p_data->create.uuid, sizeof(esp_bt_uuid_t)); memcpy(&param.create.service_id.id.uuid, &p_data->create.uuid, sizeof(esp_bt_uuid_t));
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, &param); BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, &param);
break; break;
case BTA_GATTS_ADD_INCL_SRVC_EVT: case BTA_GATTS_ADD_INCL_SRVC_EVT:

View File

@ -197,7 +197,7 @@ static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet) {
return; return;
} }
if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) { 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, " min %x, max %x", __func__, type,
DATA_TYPE_ACL, DATA_TYPE_EVENT); DATA_TYPE_ACL, DATA_TYPE_EVENT);
hci_hal_env.allocator->free(packet); hci_hal_env.allocator->free(packet);
@ -205,7 +205,7 @@ static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet) {
} }
hdr_size = preamble_sizes[type - 1]; hdr_size = preamble_sizes[type - 1];
if (packet->len < hdr_size) { 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); type, packet->len, hdr_size);
hci_hal_env.allocator->free(packet); hci_hal_env.allocator->free(packet);
return; return;

View File

@ -30,30 +30,33 @@
#include "esp_bt_main.h" #include "esp_bt_main.h"
#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_CHAR_UUID_TEST 0xFF01
#define GATTS_DESCR_UUID_TEST 0x3333 #define GATTS_DESCR_UUID_TEST 0x3333
#define APP_ID_TEST 0x18 #define APP_ID_TEST 0x18
#define GATTS_NUM_HANDLE_TEST 4 #define GATTS_NUM_HANDLE_TEST 4
#define TEST_DEVICE_NAME "snakeNB" #define TEST_DEVICE_NAME "ESP_GATTS_DEMO"
#define TEST_MANUFACTURER_DATA_LEN 8 #define TEST_MANUFACTURER_DATA_LEN 17
static uint16_t test_service_uuid = GATTS_NUM_HANDLE_TEST; static uint16_t test_service_uuid = GATTS_SERVICE_UUID_TEST;
static uint8_t test_manufacturer[TEST_MANUFACTURER_DATA_LEN] = {0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1, 0x2}; 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 = { static esp_ble_adv_data_t test_adv_data = {
.set_scan_rsp = false, .set_scan_rsp = false,
.include_name = true, .include_name = true,
.include_txpower = true, .include_txpower = true,
.min_interval = 0x20, .min_interval = 0x20,
.max_interval = 0x40, .max_interval = 0x40,
.appearance = 0, .appearance = 0x0,
.manufacturer_len = TEST_MANUFACTURER_DATA_LEN, .manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
.p_manufacturer_data = &test_manufacturer[0], .p_manufacturer_data = NULL, // &test_manufacturer[0],
.service_data_len = 0, .service_data_len = 0,
.p_service_data = NULL, .p_service_data = NULL,
.service_uuid_len = 2, .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 esp_ble_adv_params_t test_adv_params = {
@ -85,6 +88,14 @@ static struct gatts_test_inst gl_test;
static void gap_event_handler(uint32_t event, void *param) static void gap_event_handler(uint32_t event, void *param)
{ {
LOG_ERROR("GAP_EVT, event %d\n", event); 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) static void gatts_event_handler(uint32_t event, void *param)
@ -95,15 +106,15 @@ static void gatts_event_handler(uint32_t event, void *param)
case ESP_GATTS_REG_EVT: 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); 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.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.inst_id = 0x00;
gl_test.service_id.id.uuid.len = ESP_UUID_LEN_16; gl_test.service_id.id.uuid.len = ESP_UUID_LEN_16;
gl_test.service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST; 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_set_device_name(TEST_DEVICE_NAME);
esp_ble_gap_config_adv_data(&test_adv_data); 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; break;
case ESP_GATTS_READ_EVT: { 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); 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);
@ -199,7 +210,8 @@ void app_main()
esp_ble_gatts_register_callback(gatts_event_handler); esp_ble_gatts_register_callback(gatts_event_handler);
esp_ble_gap_register_callback(gap_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; return;
} }