From 0245a2028c82933f66866c71a3f139f7a99710ac Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Fri, 18 Nov 2016 22:10:35 +0800 Subject: [PATCH] component/bt : gatts fix 1. gatt server demo 2. gatt server fix bug(bta btc covert bug) 3. fix print lost --- components/bt/bluedroid/api/esp_bt_main.c | 24 +++---- components/bt/bluedroid/api/esp_gatts_api.c | 1 - .../bt/bluedroid/api/include/esp_bt_defs.h | 2 +- .../bt/bluedroid/api/include/esp_gatt_defs.h | 6 +- components/bt/bluedroid/btc/core/btc_task.c | 2 +- .../btc/profile/esp/blufi/blufi_prf.c | 4 +- .../btc/profile/std/gap/btc_gap_ble.c | 49 ++++++------- .../btc/profile/std/gatt/btc_gatt_util.c | 69 +++++++++---------- .../btc/profile/std/gatt/btc_gatts.c | 1 - components/bt/bluedroid/hci/hci_hal_h4.c | 4 +- examples/09_gatt_server/main/gatts_demo.c | 38 ++++++---- 11 files changed, 102 insertions(+), 98 deletions(-) diff --git a/components/bt/bluedroid/api/esp_bt_main.c b/components/bt/bluedroid/api/esp_bt_main.c index 3601b4c48c..d7096bd0f0 100644 --- a/components/bt/bluedroid/api/esp_bt_main.c +++ b/components/bt/bluedroid/api/esp_bt_main.c @@ -27,14 +27,14 @@ esp_err_t esp_enable_bluetooth(void) 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; } @@ -44,7 +44,7 @@ esp_err_t esp_enable_bluetooth(void) 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; } @@ -59,14 +59,14 @@ esp_err_t esp_disable_bluetooth(void) 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; } @@ -76,7 +76,7 @@ esp_err_t esp_disable_bluetooth(void) 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; } @@ -91,14 +91,14 @@ esp_err_t esp_init_bluetooth(void) 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; } @@ -110,7 +110,7 @@ esp_err_t esp_init_bluetooth(void) 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; } @@ -126,14 +126,14 @@ esp_err_t esp_deinit_bluetooth(void) 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; } @@ -143,7 +143,7 @@ esp_err_t esp_deinit_bluetooth(void) 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; } diff --git a/components/bt/bluedroid/api/esp_gatts_api.c b/components/bt/bluedroid/api/esp_gatts_api.c index f28fbcbeef..68b7453417 100644 --- a/components/bt/bluedroid/api/esp_gatts_api.c +++ b/components/bt/bluedroid/api/esp_gatts_api.c @@ -29,7 +29,6 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id) { 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; diff --git a/components/bt/bluedroid/api/include/esp_bt_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h index 9d90cbf9e7..2256c5fcac 100644 --- a/components/bt/bluedroid/api/include/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -30,7 +30,7 @@ typedef struct { 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, diff --git a/components/bt/bluedroid/api/include/esp_gatt_defs.h b/components/bt/bluedroid/api/include/esp_gatt_defs.h index 699ee66c51..ee7df8c410 100644 --- a/components/bt/bluedroid/api/include/esp_gatt_defs.h +++ b/components/bt/bluedroid/api/include/esp_gatt_defs.h @@ -70,12 +70,12 @@ typedef enum { 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 diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/bluedroid/btc/core/btc_task.c index e4c7af5fdc..ea00a8ec41 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/bluedroid/btc/core/btc_task.c @@ -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; } - 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) { diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c index b039208d69..44e459aa42 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c +++ b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c @@ -357,7 +357,7 @@ void btc_blufi_cb_handler(btc_msg_t *msg) 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; } } @@ -381,7 +381,7 @@ void btc_blufi_call_handler(btc_msg_t *msg) } break; default: - LOG_ERROR("%s UNKNOWN %d\n", msg->act); + LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act); break; } } diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 68569e7e32..d9539182d2 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -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) { - 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) @@ -204,8 +204,7 @@ 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; - + bt_uuid.len = p_adv_data->service_uuid_len; switch(bt_uuid.len) { 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) { - 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; @@ -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)); 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], @@ -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; 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{ @@ -415,7 +415,7 @@ void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params) 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); @@ -592,37 +592,38 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) 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); @@ -634,7 +635,7 @@ static void btc_gap_ble_arg_deep_free(btc_msg_t *msg) break; } default: - LOG_ERROR("Unhandled deep free\n", msg->act); + LOG_DEBUG("Unhandled deep free %d\n", msg->act); 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; - 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: diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c index baace10ad4..4e03c6bca0 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c @@ -40,71 +40,64 @@ int uuidType(unsigned char* p_uuid) 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) diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c index fe8d7bf01d..c9b878b626 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c @@ -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.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: diff --git a/components/bt/bluedroid/hci/hci_hal_h4.c b/components/bt/bluedroid/hci/hci_hal_h4.c index 7fabf83a91..07bdbdf966 100755 --- a/components/bt/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/bluedroid/hci/hci_hal_h4.c @@ -197,7 +197,7 @@ static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet) { 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); @@ -205,7 +205,7 @@ static void hci_hal_h4_hdl_rx_packet(BT_HDR *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; diff --git a/examples/09_gatt_server/main/gatts_demo.c b/examples/09_gatt_server/main/gatts_demo.c index 143786fa4e..e3634a79de 100644 --- a/examples/09_gatt_server/main/gatts_demo.c +++ b/examples/09_gatt_server/main/gatts_demo.c @@ -30,30 +30,33 @@ #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 = { @@ -85,6 +88,14 @@ static struct gatts_test_inst gl_test; 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) @@ -95,15 +106,15 @@ 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); @@ -199,7 +210,8 @@ void app_main() 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; } -- 2.40.0