mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/btdm_gatt_api' into 'master'
Feature/btdm gatt api GATT upstream api changed. Actually, feature/btdm_blufi based on this branch. See merge request !366
This commit is contained in:
commit
f867e0671e
@ -22,7 +22,7 @@
|
||||
#include "btc_main.h"
|
||||
#include "future.h"
|
||||
|
||||
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback)
|
||||
esp_err_t esp_blufi_register_callback(esp_blufi_cb_t callback)
|
||||
{
|
||||
return (btc_profile_cb_set(BTC_PID_BLUFI, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "btc_gap_ble.h"
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback)
|
||||
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback)
|
||||
{
|
||||
return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -17,8 +17,9 @@
|
||||
#include "esp_gattc_api.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gattc.h"
|
||||
#include "btc_gatt_util.h"
|
||||
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback)
|
||||
{
|
||||
if (callback == NULL) {
|
||||
return ESP_FAIL;
|
||||
@ -33,7 +34,6 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
|
||||
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
|
||||
if (app_id > ESP_APP_ID_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@ -46,7 +46,7 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -54,12 +54,12 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_APP_UNREGISTER;
|
||||
arg.app_unreg.gatt_if = gatt_if;
|
||||
arg.app_unreg.gattc_if = gattc_if;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -67,14 +67,14 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_OPEN;
|
||||
arg.open.gatt_if = gatt_if;
|
||||
arg.open.gattc_if = gattc_if;
|
||||
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
|
||||
arg.open.is_direct = is_direct;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_close (uint16_t conn_id)
|
||||
esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -82,12 +82,12 @@ esp_err_t esp_ble_gattc_close (uint16_t conn_id)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_CLOSE;
|
||||
arg.close.conn_id = conn_id;
|
||||
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
|
||||
esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -99,13 +99,13 @@ esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_CFG_MTU;
|
||||
arg.cfg_mtu.conn_id = conn_id;
|
||||
arg.cfg_mtu.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
arg.cfg_mtu.mtu = mtu;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
|
||||
esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -113,7 +113,8 @@ esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_u
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_SEARCH_SERVICE;
|
||||
arg.search_srvc.conn_id = conn_id;
|
||||
arg.search_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
|
||||
if (filter_uuid) {
|
||||
arg.search_srvc.filter_uuid_enable = true;
|
||||
memcpy(&arg.search_srvc.filter_uuid, filter_uuid, sizeof(esp_bt_uuid_t));
|
||||
@ -124,9 +125,10 @@ esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_u
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *start_char_id)
|
||||
esp_err_t esp_ble_gattc_get_characteristic(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *start_char_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -134,12 +136,12 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
if (start_char_id) {
|
||||
arg.get_next_char.conn_id = conn_id;
|
||||
arg.get_next_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.get_next_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.get_next_char.char_id, start_char_id, sizeof(esp_gatt_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_NEXT_CHAR;
|
||||
} else {
|
||||
arg.get_first_char.conn_id = conn_id;
|
||||
arg.get_first_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.get_first_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_FIRST_CHAR;
|
||||
}
|
||||
@ -147,7 +149,8 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
esp_err_t esp_ble_gattc_get_descriptor(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *start_descr_id)
|
||||
@ -159,13 +162,13 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
|
||||
if (start_descr_id) {
|
||||
arg.get_next_descr.conn_id = conn_id;
|
||||
arg.get_next_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.get_next_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.get_next_descr.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
memcpy(&arg.get_next_descr.descr_id, start_descr_id, sizeof(esp_gatt_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_NEXT_DESCR;
|
||||
} else {
|
||||
arg.get_first_descr.conn_id = conn_id;
|
||||
arg.get_first_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.get_first_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.get_first_descr.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_FIRST_DESCR;
|
||||
@ -174,9 +177,10 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_srvc_id_t *start_incl_srvc_id)
|
||||
esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_srvc_id_t *start_incl_srvc_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -185,12 +189,12 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
|
||||
if (start_incl_srvc_id) {
|
||||
arg.get_next_incl_srvc.conn_id = conn_id;
|
||||
arg.get_next_incl_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.get_next_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.get_next_incl_srvc.start_service_id, start_incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE;
|
||||
} else {
|
||||
arg.get_first_incl_srvc.conn_id = conn_id;
|
||||
arg.get_first_incl_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.get_first_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE;
|
||||
}
|
||||
@ -198,8 +202,11 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id, esp_gatt_auth_req_t auth_req)
|
||||
esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -207,7 +214,7 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_READ_CHAR;
|
||||
arg.read_char.conn_id = conn_id;
|
||||
arg.read_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.read_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.read_char.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
arg.read_char.auth_req = auth_req;
|
||||
@ -215,11 +222,12 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -227,7 +235,7 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_READ_CHAR_DESCR;
|
||||
arg.read_descr.conn_id = conn_id;
|
||||
arg.read_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.read_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.read_descr.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
memcpy(&arg.read_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
|
||||
@ -236,7 +244,8 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t value_len,
|
||||
@ -250,7 +259,7 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_WRITE_CHAR;
|
||||
arg.write_char.conn_id = (uint16_t) conn_id;
|
||||
arg.write_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.write_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.write_char.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
arg.write_char.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
|
||||
@ -261,14 +270,15 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -276,7 +286,7 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_WRITE_CHAR_DESCR;
|
||||
arg.write_descr.conn_id = (uint16_t) conn_id;
|
||||
arg.write_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.write_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.write_descr.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
memcpy(&arg.write_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
|
||||
@ -288,7 +298,8 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t offset,
|
||||
@ -303,7 +314,7 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_PREPARE_WRITE;
|
||||
arg.prep_write.conn_id = conn_id;
|
||||
arg.prep_write.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
memcpy(&arg.prep_write.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.prep_write.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
arg.prep_write.offset = offset;
|
||||
@ -314,7 +325,7 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
|
||||
esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
@ -322,13 +333,13 @@ esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_EXECUTE_WRITE;
|
||||
arg.exec_write.conn_id = conn_id;
|
||||
arg.exec_write.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
|
||||
arg.exec_write.is_execute = is_execute;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id)
|
||||
@ -339,7 +350,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_REG_FOR_NOTIFY;
|
||||
arg.reg_for_notify.gatt_if = gatt_if;
|
||||
arg.reg_for_notify.gattc_if = gattc_if;
|
||||
memcpy(arg.reg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
|
||||
memcpy(&arg.reg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.reg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
@ -347,7 +358,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id)
|
||||
@ -358,7 +369,7 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_UNREG_FOR_NOTIFY;
|
||||
arg.unreg_for_notify.gatt_if = gatt_if;
|
||||
arg.unreg_for_notify.gattc_if = gattc_if;
|
||||
memcpy(arg.unreg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
|
||||
memcpy(&arg.unreg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.unreg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
|
@ -17,10 +17,11 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gatts.h"
|
||||
#include "btc_gatt_util.h"
|
||||
|
||||
#define COPY_TO_GATTS_ARGS(_gatt_args, _arg, _arg_type) memcpy(_gatt_args, _arg, sizeof(_arg_type))
|
||||
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback)
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback)
|
||||
{
|
||||
return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -44,7 +45,7 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
@ -52,12 +53,12 @@ esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_APP_UNREGISTER;
|
||||
arg.app_unreg.gatt_if = gatt_if;
|
||||
arg.app_unreg.gatts_if = gatts_if;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
|
||||
esp_gatt_srvc_id_t *service_id, uint16_t num_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@ -66,7 +67,7 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_CREATE_SERVICE;
|
||||
arg.create_srvc.gatt_if = gatt_if;
|
||||
arg.create_srvc.gatts_if = gatts_if;
|
||||
arg.create_srvc.num_handle = num_handle;
|
||||
memcpy(&arg.create_srvc.service_id, service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
|
||||
@ -164,7 +165,7 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
esp_err_t esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id, uint16_t attr_handle,
|
||||
uint16_t value_len, uint8_t *value, bool need_confirm)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@ -173,7 +174,7 @@ esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_SEND_INDICATE;
|
||||
arg.send_ind.conn_id = conn_id;
|
||||
arg.send_ind.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
||||
arg.send_ind.attr_handle = attr_handle;
|
||||
arg.send_ind.need_confirm = need_confirm;
|
||||
arg.send_ind.value_len = value_len;
|
||||
@ -182,7 +183,7 @@ esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
esp_err_t esp_ble_gatts_send_response(esp_gatt_if_t gatts_if, uint16_t conn_id, uint32_t trans_id,
|
||||
esp_gatt_status_t status, esp_gatt_rsp_t *rsp)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@ -191,7 +192,7 @@ esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_SEND_RESPONSE;
|
||||
arg.send_rsp.conn_id = conn_id;
|
||||
arg.send_rsp.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
||||
arg.send_rsp.trans_id = trans_id;
|
||||
arg.send_rsp.status = status;
|
||||
arg.send_rsp.rsp = rsp;
|
||||
@ -199,7 +200,7 @@ esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
@ -207,14 +208,14 @@ esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_OPEN;
|
||||
arg.open.gatt_if = gatt_if;
|
||||
arg.open.gatts_if = gatts_if;
|
||||
arg.open.is_direct = is_direct;
|
||||
memcpy(&arg.open.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_close(uint16_t conn_id)
|
||||
esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
@ -222,7 +223,7 @@ esp_err_t esp_ble_gatts_close(uint16_t conn_id)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_CLOSE;
|
||||
arg.close.conn_id = conn_id;
|
||||
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -25,9 +25,11 @@ extern "C" {
|
||||
|
||||
#define ESP_BLUFI_RECV_DATA_LEN_MAX (64+1)
|
||||
|
||||
#define ESP_BLUFI_EVENT_INIT_FINISH 0
|
||||
#define ESP_BLUFI_EVENT_DEINIT_FINISH 1
|
||||
#define ESP_BLUFI_EVENT_RECV_DATA 2
|
||||
typedef enum {
|
||||
ESP_BLUFI_EVENT_INIT_FINISH = 0,
|
||||
ESP_BLUFI_EVENT_DEINIT_FINISH = 1,
|
||||
ESP_BLUFI_EVENT_RECV_DATA = 2,
|
||||
} esp_blufi_cb_event_t;
|
||||
|
||||
/// BLUFI config status
|
||||
typedef enum {
|
||||
@ -74,6 +76,14 @@ typedef union {
|
||||
} recv_data; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_DATA */
|
||||
} esp_blufi_cb_param_t;
|
||||
|
||||
/**
|
||||
* @brief BLUFI callback function type
|
||||
* @param event : Event type
|
||||
* @param param : Point to callback parameter, currently is union type
|
||||
*/
|
||||
typedef void (* esp_blufi_cb_t)(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to receive blufi callback event
|
||||
@ -83,7 +93,7 @@ typedef union {
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback);
|
||||
esp_err_t esp_blufi_register_callback(esp_blufi_cb_t callback);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -96,13 +96,6 @@ typedef enum {
|
||||
/// Maximum of the application id
|
||||
#define ESP_APP_ID_MAX 0x7fff
|
||||
|
||||
/**
|
||||
* @brief Each profile callback function type
|
||||
* @param event : Event type
|
||||
* @param param : Point to callback parameter, currently is union type
|
||||
*/
|
||||
typedef void (* esp_profile_cb_t)(uint32_t event, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@ typedef enum {
|
||||
ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT , /*!< When scan response data set complete, the event comes */
|
||||
ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, /*!< When scan parameters set complete, the event comes */
|
||||
ESP_GAP_BLE_SCAN_RESULT_EVT, /*!< When one scan result ready, the event comes each time */
|
||||
}esp_gap_ble_cb_event_t;
|
||||
} esp_gap_ble_cb_event_t;
|
||||
|
||||
/// Advertising data maximum length
|
||||
#define ESP_BLE_ADV_DATA_LEN_MAX 31
|
||||
@ -257,6 +257,13 @@ typedef union {
|
||||
} scan_rst; /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */
|
||||
} esp_ble_gap_cb_param_t;
|
||||
|
||||
/**
|
||||
* @brief GAP callback function type
|
||||
* @param event : Event type
|
||||
* @param param : Point to callback parameter, currently is union type
|
||||
*/
|
||||
typedef void (* esp_gap_ble_cb_t)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief This function is called to occur gap event, such as scan result
|
||||
*
|
||||
@ -267,7 +274,7 @@ typedef union {
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback);
|
||||
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -269,7 +269,9 @@ typedef enum {
|
||||
ESP_GATT_WRITE_TYPE_RSP, /*!< Gatt write attribute need remote response */
|
||||
} esp_gatt_write_type_t;
|
||||
|
||||
typedef uint32_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */
|
||||
#define ESP_GATT_IF_NONE 0xff /*!< If callback report gattc_if/gatts_if as this macro, means this event is not correspond to any app */
|
||||
|
||||
typedef uint8_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ typedef union {
|
||||
*/
|
||||
struct gattc_reg_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t app_id; /*!< Application id which input in register API */
|
||||
} reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */
|
||||
|
||||
@ -91,7 +90,6 @@ typedef union {
|
||||
struct gattc_open_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
uint16_t mtu; /*!< MTU size */
|
||||
} open; /*!< Gatt client callback param of ESP_GATTC_OPEN_EVT */
|
||||
@ -102,7 +100,6 @@ typedef union {
|
||||
struct gattc_close_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
esp_gatt_conn_reason_t reason; /*!< The reason of gatt connection close */
|
||||
} close; /*!< Gatt client callback param of ESP_GATTC_CLOSE_EVT */
|
||||
@ -247,6 +244,14 @@ typedef union {
|
||||
|
||||
} esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */
|
||||
|
||||
/**
|
||||
* @brief GATT Client callback function type
|
||||
* @param event : Event type
|
||||
* @param gatts_if : GATT client access interface, normally
|
||||
* different gattc_if correspond to different profile
|
||||
* @param param : Point to callback parameter, currently is union type
|
||||
*/
|
||||
typedef void (* esp_gattc_cb_t)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief This function is called to register application callbacks
|
||||
@ -259,7 +264,7 @@ typedef union {
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback);
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback);
|
||||
|
||||
|
||||
/**
|
||||
@ -280,20 +285,20 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
|
||||
* @brief This function is called to unregister an application
|
||||
* from GATTC module.
|
||||
*
|
||||
* @param[in] gatt_if : app identifier.
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if);
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Open a direct connection or add a background auto connection
|
||||
*
|
||||
* @param[in] gatt_if: application identity.
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] remote_bda: remote device bluetooth device address.
|
||||
* @param[in] is_direct: direct connection or background auto connection
|
||||
*
|
||||
@ -302,12 +307,13 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if);
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Close a connection to a GATT server.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id: connection ID to be closed.
|
||||
*
|
||||
* @return
|
||||
@ -315,13 +321,14 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_close(uint16_t conn_id);
|
||||
esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configure the MTU size in the GATT channel. This can be done
|
||||
* only once per connection.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id: connection ID.
|
||||
* @param[in] mtu: desired MTU size to use.
|
||||
*
|
||||
@ -330,7 +337,7 @@ esp_err_t esp_ble_gattc_close(uint16_t conn_id);
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_config_mtu(uint16_t conn_id, uint16_t mtu);
|
||||
esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu);
|
||||
|
||||
|
||||
/**
|
||||
@ -339,6 +346,7 @@ esp_err_t esp_ble_gattc_config_mtu(uint16_t conn_id, uint16_t mtu);
|
||||
* by a callback event, and followed by a service search complete
|
||||
* event.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id: connection ID.
|
||||
* @param[in] filter_uuid: a UUID of the service application is interested in.
|
||||
* If Null, discover for all services.
|
||||
@ -348,32 +356,32 @@ esp_err_t esp_ble_gattc_config_mtu(uint16_t conn_id, uint16_t mtu);
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
|
||||
esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to find the first characteristic of the
|
||||
* service on the given server.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id: connection ID which identify the server.
|
||||
*
|
||||
* @param[in] srvc_id: service ID
|
||||
*
|
||||
* @param[in] start_char_id: the start characteristic ID
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *start_char_id);
|
||||
|
||||
esp_err_t esp_ble_gattc_get_characteristic(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *start_char_id);
|
||||
|
||||
/**
|
||||
* @brief This function is called to find the descriptor of the
|
||||
* service on the given server.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id: connection ID which identify the server.
|
||||
* @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
* @param[in] char_id: Characteristic ID, if NULL find the first available
|
||||
@ -385,8 +393,10 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *char_id,
|
||||
esp_err_t esp_ble_gattc_get_descriptor(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *start_descr_id);
|
||||
|
||||
|
||||
@ -394,6 +404,7 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
* @brief This function is called to find the first characteristic of the
|
||||
* service on the given server.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id: connection ID which identify the server.
|
||||
* @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
* @param[in] start_incl_srvc_id: the start include service id
|
||||
@ -403,14 +414,17 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_srvc_id_t *start_incl_srvc_id);
|
||||
esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_srvc_id_t *start_incl_srvc_id);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to read a service's characteristics of
|
||||
* the given characteriistic ID
|
||||
* the given characteristic ID
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID to read.
|
||||
@ -421,15 +435,17 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to read a characteristics descriptor.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID to read.
|
||||
@ -441,16 +457,18 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to write characteristic value.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID to write.
|
||||
@ -464,7 +482,8 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t value_len,
|
||||
@ -476,6 +495,7 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
/**
|
||||
* @brief This function is called to write characteristic descriptor value.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id : connection ID
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID.
|
||||
@ -490,19 +510,21 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to prepare write a characteristic value.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : GATT characteristic ID of the service.
|
||||
@ -516,7 +538,8 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if,
|
||||
uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t offset,
|
||||
@ -524,9 +547,11 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
uint8_t *value,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to execute write a prepare write sequence.
|
||||
*
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] is_execute : execute or cancel.
|
||||
*
|
||||
@ -535,13 +560,13 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute);
|
||||
esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to register for notification of a service.
|
||||
*
|
||||
* @param[in] gatt_if : gatt interface id.
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] server_bda : target GATT server.
|
||||
* @param[in] srvc_id : pointer to GATT service ID.
|
||||
* @param[in] char_id : pointer to GATT characteristic ID.
|
||||
@ -551,16 +576,16 @@ esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute);
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-register for notification of a service.
|
||||
*
|
||||
* @param[in] gatt_if : gatt interface id.
|
||||
* @param[in] gattc_if: Gatt client access interface.
|
||||
* @param[in] server_bda : target GATT server.
|
||||
* @param[in] srvc_id : pointer to GATT service ID.
|
||||
* @param[in] char_id : pointer to GATT characteristic ID.
|
||||
@ -570,10 +595,10 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_reg_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t app_id; /*!< Application id which input in register API */
|
||||
} reg; /*!< Gatt server callback param of ESP_GATTS_REG_EVT */
|
||||
|
||||
@ -127,7 +126,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_create_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
esp_gatt_srvc_id_t service_id; /*!< Service id, include service uuid and other information */
|
||||
} create; /*!< Gatt server callback param of ESP_GATTS_CREATE_EVT */
|
||||
@ -137,7 +135,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_add_incl_srvc_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t attr_handle; /*!< Included service attribute handle */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} add_incl_srvc; /*!< Gatt server callback param of ESP_GATTS_ADD_INCL_SRVC_EVT */
|
||||
@ -147,7 +144,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_add_char_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t attr_handle; /*!< Characteristic attribute handle */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
esp_bt_uuid_t char_uuid; /*!< Characteristic uuid */
|
||||
@ -158,7 +154,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_add_char_descr_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t attr_handle; /*!< Descriptor attribute handle */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
esp_bt_uuid_t char_uuid; /*!< Characteristic uuid */
|
||||
@ -169,7 +164,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_delete_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} del; /*!< Gatt server callback param of ESP_GATTS_DELETE_EVT */
|
||||
|
||||
@ -178,7 +172,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_start_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} start; /*!< Gatt server callback param of ESP_GATTS_START_EVT */
|
||||
|
||||
@ -187,7 +180,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_stop_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} stop; /*!< Gatt server callback param of ESP_GATTS_STOP_EVT */
|
||||
|
||||
@ -196,7 +188,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_connect_evt_param {
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
bool is_connected; /*!< Indicate it is connected or not */
|
||||
} connect; /*!< Gatt server callback param of ESP_GATTS_CONNECT_EVT */
|
||||
@ -206,7 +197,6 @@ typedef union {
|
||||
*/
|
||||
struct gatts_disconnect_evt_param {
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
bool is_connected; /*!< Indicate it is connected or not */
|
||||
} disconnect; /*!< Gatt server callback param of ESP_GATTS_DISCONNECT_EVT */
|
||||
@ -240,6 +230,15 @@ typedef union {
|
||||
} rsp; /*!< Gatt server callback param of ESP_GATTS_RESPONSE_EVT */
|
||||
} esp_ble_gatts_cb_param_t;
|
||||
|
||||
/**
|
||||
* @brief GATT Server callback function type
|
||||
* @param event : Event type
|
||||
* @param gatts_if : GATT server access interface, normally
|
||||
* different gatts_if correspond to different profile
|
||||
* @param param : Point to callback parameter, currently is union type
|
||||
*/
|
||||
typedef void (* esp_gatts_cb_t)(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief This function is called to register application callbacks
|
||||
* with BTA GATTS module.
|
||||
@ -249,9 +248,7 @@ typedef union {
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback);
|
||||
|
||||
/**
|
||||
* @brief This function is called to register application identifier
|
||||
@ -268,14 +265,13 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id);
|
||||
/**
|
||||
* @brief unregister with GATT Server.
|
||||
*
|
||||
* @param[in] gatt_if: gatt interface id.
|
||||
*
|
||||
* @param[in] gatts_if: GATT server access interface
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if);
|
||||
|
||||
|
||||
/**
|
||||
@ -285,7 +281,7 @@ esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
|
||||
* the callback function needs to be used when adding included
|
||||
* service and characteristics/descriptors into the service.
|
||||
*
|
||||
* @param[in] gatt_if: gatt interface ID
|
||||
* @param[in] gatts_if: GATT server access interface
|
||||
* @param[in] service_id: service ID.
|
||||
* @param[in] num_handle: number of handle requested for this service.
|
||||
*
|
||||
@ -294,7 +290,7 @@ esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
|
||||
esp_gatt_srvc_id_t *service_id, uint16_t num_handle);
|
||||
|
||||
|
||||
@ -402,6 +398,7 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle);
|
||||
/**
|
||||
* @brief This function is called to read a characteristics descriptor.
|
||||
*
|
||||
* @param[in] gatts_if: GATT server access interface
|
||||
* @param[in] conn_id - connection id to indicate.
|
||||
* @param[in] attr_handle - attribute handle to indicate.
|
||||
* @param[in] value_len - indicate value length.
|
||||
@ -413,13 +410,14 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle);
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
esp_err_t esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id, uint16_t attr_handle,
|
||||
uint16_t value_len, uint8_t *value, bool need_confirm);
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to send a response to a request.
|
||||
*
|
||||
* @param[in] gatts_if: GATT server access interface
|
||||
* @param[in] conn_id - connection identifier.
|
||||
* @param[in] trans_id - transfer id
|
||||
* @param[in] status - response status
|
||||
@ -430,14 +428,14 @@ esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
esp_err_t esp_ble_gatts_send_response(esp_gatt_if_t gatts_if, uint16_t conn_id, uint32_t trans_id,
|
||||
esp_gatt_status_t status, esp_gatt_rsp_t *rsp);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Open a direct open connection or add a background auto connection
|
||||
*
|
||||
* @param[in] gatt_if: application ID.
|
||||
* @param[in] gatts_if: GATT server access interface
|
||||
* @param[in] remote_bda: remote device bluetooth device address.
|
||||
* @param[in] is_direct: direct connection or background auto connection
|
||||
*
|
||||
@ -446,11 +444,12 @@ esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct);
|
||||
|
||||
/**
|
||||
* @brief Close a connection a remote device.
|
||||
*
|
||||
* @param[in] gatts_if: GATT server access interface
|
||||
* @param[in] conn_id: connection ID to be closed.
|
||||
*
|
||||
* @return
|
||||
@ -458,7 +457,7 @@ esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_close(uint16_t conn_id);
|
||||
esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
|
||||
static esp_profile_cb_t btc_profile_cb_tab[BTC_PID_NUM] = {};
|
||||
static void *btc_profile_cb_tab[BTC_PID_NUM] = {};
|
||||
|
||||
void esp_profile_cb_reset(void)
|
||||
{
|
||||
@ -31,7 +31,7 @@ void esp_profile_cb_reset(void)
|
||||
}
|
||||
}
|
||||
|
||||
int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb)
|
||||
int btc_profile_cb_set(btc_pid_t profile_id, void *cb)
|
||||
{
|
||||
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
|
||||
return -1;
|
||||
@ -42,7 +42,7 @@ int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
esp_profile_cb_t btc_profile_cb_get(btc_pid_t profile_id)
|
||||
void *btc_profile_cb_get(btc_pid_t profile_id)
|
||||
{
|
||||
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
|
||||
return NULL;
|
||||
|
@ -22,7 +22,7 @@
|
||||
/* reset gatt callback table */
|
||||
void esp_profile_cb_reset(void);
|
||||
|
||||
int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb);
|
||||
esp_profile_cb_t btc_profile_cb_get(btc_pid_t profile_id);
|
||||
int btc_profile_cb_set(btc_pid_t profile_id, void *cb);
|
||||
void *btc_profile_cb_get(btc_pid_t profile_id);
|
||||
|
||||
#endif /* __BTC_MANAGE_H__ */
|
||||
|
@ -37,7 +37,7 @@
|
||||
const char success_msg[] = "BLUFI_CONFIG_OK";
|
||||
const char failed_msg[] = "BLUFI_CONFIG_FAILED";
|
||||
|
||||
#define BTC_BLUFI_CB_TO_APP(_event, _param) ((esp_profile_cb_t)btc_profile_cb_get(BTC_PID_BLUFI))(_event, _param)
|
||||
#define BTC_BLUFI_CB_TO_APP(event, param) ((esp_blufi_cb_t)btc_profile_cb_get(BTC_PID_BLUFI))((event), (param))
|
||||
|
||||
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
||||
@ -147,6 +147,8 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
|
||||
UINT8 *p_rec_data = NULL;
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
|
||||
tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
|
||||
|
||||
LOG_DEBUG("blufi profile cb event = %x\n", event);
|
||||
switch (event) {
|
||||
@ -166,6 +168,8 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
event, status, blufi_cb_env.gatt_if);
|
||||
|
||||
LOG_DEBUG("set advertising parameters\n");
|
||||
//set connectable,discoverable, pairable and paired only modes of local device
|
||||
BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL);
|
||||
//set the advertising data to the btm layer
|
||||
BlufiBleConfigadvData(&esp32_adv_data[BLE_ADV_DATA_IDX], NULL);
|
||||
//set the adversting data to the btm layer
|
||||
|
@ -26,7 +26,7 @@
|
||||
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
|
||||
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
|
||||
|
||||
#define BTC_GAP_BLE_CB_TO_APP(_event, _param) ((esp_profile_cb_t )btc_profile_cb_get(BTC_PID_GAP_BLE))(_event, _param)
|
||||
#define BTC_GAP_BLE_CB_TO_APP(event, param) ((esp_gap_ble_cb_t)btc_profile_cb_get(BTC_PID_GAP_BLE))((event), (param))
|
||||
|
||||
|
||||
static void btc_gap_adv_point_cleanup(void **buf)
|
||||
|
@ -169,13 +169,14 @@ uint16_t get_uuid16(tBT_UUID *p_uuid)
|
||||
return (UINT16) p_uuid->uu.uuid32;
|
||||
}
|
||||
}
|
||||
uint16_t set_read_value(esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src)
|
||||
uint16_t set_read_value(uint8_t *gattc_if, esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src)
|
||||
{
|
||||
uint16_t descr_type = 0;
|
||||
uint16_t len = 0;
|
||||
|
||||
p_dest->read.status = p_src->status;
|
||||
p_dest->read.conn_id = p_src->conn_id;
|
||||
p_dest->read.conn_id = BTC_GATT_GET_CONN_ID(p_src->conn_id);
|
||||
*gattc_if = BTC_GATT_GET_GATT_IF(p_src->conn_id);
|
||||
bta_to_btc_srvc_id(&p_dest->read.srvc_id, &p_src->srvc_id);
|
||||
bta_to_btc_gatt_id(&p_dest->read.char_id, &p_src->char_id);
|
||||
bta_to_btc_gatt_id(&p_dest->read.descr_id, &p_src->descr_type);
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "bt_trace.h"
|
||||
#include "esp_gattc_api.h"
|
||||
|
||||
#define BTC_GATTC_CB_TO_APP(_event, _param) ((esp_profile_cb_t )btc_profile_cb_get(BTC_PID_GATTC))(_event, _param)
|
||||
#define BTC_GATTC_CB_TO_APP(event, gattc_if, param) ((esp_gattc_cb_t )btc_profile_cb_get(BTC_PID_GATTC))((event), (gattc_if), (param))
|
||||
|
||||
void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
@ -141,13 +141,13 @@ static void btc_gattc_app_register(btc_ble_gattc_args_t *arg)
|
||||
|
||||
static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg)
|
||||
{
|
||||
BTA_GATTC_AppDeregister(arg->app_unreg.gatt_if);
|
||||
BTA_GATTC_AppDeregister(arg->app_unreg.gattc_if);
|
||||
}
|
||||
|
||||
static void btc_gattc_open(btc_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
|
||||
BTA_GATTC_Open(arg->open.gatt_if, arg->open.remote_bda, arg->open.is_direct, transport);
|
||||
BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda, arg->open.is_direct, transport);
|
||||
}
|
||||
|
||||
static void btc_gattc_close(btc_ble_gattc_args_t *arg)
|
||||
@ -181,6 +181,7 @@ static void btc_gattc_get_first_char(btc_ble_gattc_args_t *arg)
|
||||
tBTA_GATT_CHAR_PROP out_char_prop;
|
||||
tBTA_GATT_SRVC_ID srvc_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
esp_gatt_if_t gattc_if;
|
||||
|
||||
btc_to_bta_srvc_id(&srvc_id, &arg->get_first_char.service_id);
|
||||
status = BTA_GATTC_GetFirstChar(arg->get_first_char.conn_id, &srvc_id, NULL,
|
||||
@ -189,13 +190,14 @@ static void btc_gattc_get_first_char(btc_ble_gattc_args_t *arg)
|
||||
bta_to_btc_gatt_id(&char_id, &out_char_id.char_id);
|
||||
}
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_first_char.conn_id);
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_char.conn_id = arg->get_first_char.conn_id;
|
||||
param.get_char.conn_id = BTC_GATT_GET_CONN_ID(arg->get_first_char.conn_id);
|
||||
param.get_char.status = status;
|
||||
memcpy(¶m.get_char.srvc_id, &arg->get_first_char.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
|
||||
param.get_char.char_prop = out_char_prop;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, gattc_if, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
|
||||
@ -206,6 +208,8 @@ static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
|
||||
tBTA_GATTC_CHAR_ID out_char_id;
|
||||
tBTA_GATT_CHAR_PROP out_char_prop;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
esp_gatt_if_t gattc_if;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->get_next_char.service_id);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->get_next_char.char_id);
|
||||
|
||||
@ -216,13 +220,14 @@ static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
|
||||
bta_to_btc_gatt_id(&char_id, &out_char_id.char_id);
|
||||
}
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_next_char.conn_id);
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_char.conn_id = arg->get_next_char.conn_id;
|
||||
param.get_char.conn_id = BTC_GATT_GET_CONN_ID(arg->get_next_char.conn_id);
|
||||
param.get_char.status = status;
|
||||
memcpy(¶m.get_char.srvc_id, &arg->get_next_char.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
|
||||
param.get_char.char_prop = out_char_prop;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, gattc_if, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
|
||||
@ -232,6 +237,7 @@ static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
tBTA_GATTC_CHAR_DESCR_ID out_char_descr_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
esp_gatt_if_t gattc_if;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->get_first_descr.service_id);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->get_first_descr.char_id);
|
||||
@ -243,13 +249,14 @@ static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
|
||||
bta_to_btc_gatt_id(&descr_id, &out_char_descr_id.descr_id);
|
||||
}
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_first_descr.conn_id);
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_descr.conn_id = arg->get_first_descr.conn_id;
|
||||
param.get_descr.conn_id = BTC_GATT_GET_CONN_ID(arg->get_first_descr.conn_id);
|
||||
param.get_descr.status = status;
|
||||
memcpy(¶m.get_descr.srvc_id, &arg->get_first_descr.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_descr.char_id, &arg->get_first_descr.char_id, sizeof(esp_gatt_id_t));
|
||||
memcpy(¶m.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, gattc_if, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
|
||||
@ -259,6 +266,7 @@ static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
|
||||
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
|
||||
tBTA_GATTC_CHAR_DESCR_ID out_char_descr_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
esp_gatt_if_t gattc_if;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &arg->get_next_descr.service_id);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &arg->get_next_descr.char_id);
|
||||
@ -270,13 +278,14 @@ static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
|
||||
bta_to_btc_gatt_id(&descr_id, &out_char_descr_id.descr_id);
|
||||
}
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_next_descr.conn_id);
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_descr.conn_id = arg->get_next_descr.conn_id;
|
||||
param.get_descr.conn_id = BTC_GATT_GET_CONN_ID(arg->get_next_descr.conn_id);
|
||||
param.get_descr.status = status;
|
||||
memcpy(¶m.get_descr.srvc_id, &arg->get_next_descr.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_descr.char_id, &arg->get_next_descr.char_id, sizeof(esp_gatt_id_t));
|
||||
memcpy(¶m.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, gattc_if, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
|
||||
@ -286,6 +295,7 @@ static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
|
||||
tBTA_GATT_SRVC_ID srvc_id;
|
||||
tBTA_GATTC_INCL_SVC_ID out_incl_svc_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
esp_gatt_if_t gattc_if;
|
||||
|
||||
btc_to_bta_srvc_id(&srvc_id, &arg->get_first_incl_srvc.service_id);
|
||||
|
||||
@ -294,12 +304,13 @@ static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
|
||||
|
||||
bta_to_btc_srvc_id(&incl_srvc_id, &out_incl_svc_id.incl_svc_id);
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_first_incl_srvc.conn_id);
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_incl_srvc.conn_id = arg->get_first_incl_srvc.conn_id;
|
||||
param.get_incl_srvc.conn_id = BTC_GATT_GET_CONN_ID(arg->get_first_incl_srvc.conn_id);
|
||||
param.get_incl_srvc.status = status;
|
||||
memcpy(¶m.get_incl_srvc.srvc_id, &arg->get_first_incl_srvc.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
|
||||
@ -309,6 +320,7 @@ static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
|
||||
tBTA_GATTC_INCL_SVC_ID in_incl_svc_id;
|
||||
tBTA_GATTC_INCL_SVC_ID out_incl_svc_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
esp_gatt_if_t gattc_if;
|
||||
|
||||
btc_to_bta_srvc_id(&in_incl_svc_id.srvc_id, &arg->get_next_incl_srvc.service_id);
|
||||
btc_to_bta_srvc_id(&in_incl_svc_id.incl_svc_id, &arg->get_next_incl_srvc.start_service_id);
|
||||
@ -318,12 +330,13 @@ static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
|
||||
|
||||
bta_to_btc_srvc_id(&incl_srvc_id, &out_incl_svc_id.incl_svc_id);
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(arg->get_next_incl_srvc.conn_id);
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_incl_srvc.conn_id = arg->get_next_incl_srvc.conn_id;
|
||||
param.get_incl_srvc.conn_id = BTC_GATT_GET_CONN_ID(arg->get_next_incl_srvc.conn_id);
|
||||
param.get_incl_srvc.status = status;
|
||||
memcpy(¶m.get_incl_srvc.srvc_id, &arg->get_next_incl_srvc.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_read_char(btc_ble_gattc_args_t *arg)
|
||||
@ -402,15 +415,15 @@ static void btc_gattc_reg_for_notify(btc_ble_gattc_args_t *arg)
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->reg_for_notify.service_id);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->reg_for_notify.char_id);
|
||||
|
||||
status = BTA_GATTC_RegisterForNotifications(arg->reg_for_notify.gatt_if,
|
||||
status = BTA_GATTC_RegisterForNotifications(arg->reg_for_notify.gattc_if,
|
||||
arg->reg_for_notify.remote_bda,
|
||||
&in_char_id);
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.reg_for_notify.status = status;
|
||||
memcpy(¶m.reg_for_notify.srvc_id, &arg->reg_for_notify.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.reg_for_notify.char_id, &arg->reg_for_notify.service_id, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_FOR_NOTIFY_EVT, ¶m);
|
||||
memcpy(¶m.reg_for_notify.char_id, &arg->reg_for_notify.char_id, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_FOR_NOTIFY_EVT, arg->reg_for_notify.gattc_if, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
|
||||
@ -422,7 +435,7 @@ static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->unreg_for_notify.service_id);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->unreg_for_notify.char_id);
|
||||
|
||||
status = BTA_GATTC_DeregisterForNotifications(arg->unreg_for_notify.gatt_if,
|
||||
status = BTA_GATTC_DeregisterForNotifications(arg->unreg_for_notify.gattc_if,
|
||||
arg->unreg_for_notify.remote_bda,
|
||||
&in_char_id);
|
||||
|
||||
@ -430,7 +443,7 @@ static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
|
||||
param.unreg_for_notify.status = status;
|
||||
memcpy(¶m.unreg_for_notify.srvc_id, &arg->unreg_for_notify.service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.unreg_for_notify.char_id, &arg->unreg_for_notify.service_id, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_FOR_NOTIFY_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_FOR_NOTIFY_EVT, arg->unreg_for_notify.gattc_if, ¶m);
|
||||
}
|
||||
|
||||
void btc_gattc_call_handler(btc_msg_t *msg)
|
||||
@ -508,6 +521,7 @@ void btc_gattc_call_handler(btc_msg_t *msg)
|
||||
void btc_gattc_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg);
|
||||
esp_gatt_if_t gattc_if;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
@ -515,75 +529,90 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTA_GATTC_REG_EVT: {
|
||||
tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
|
||||
|
||||
gattc_if = reg_oper->client_if;
|
||||
param.reg.status = reg_oper->status;
|
||||
param.reg.gatt_if = reg_oper->client_if;
|
||||
param.reg.app_id = reg_oper->app_uuid.uu.uuid16;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_DEREG_EVT: {
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_EVT, NULL);
|
||||
tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
|
||||
|
||||
gattc_if = reg_oper->client_if;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_EVT, gattc_if, NULL);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_READ_CHAR_EVT: {
|
||||
set_read_value(¶m, &arg->read);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_CHAR_EVT, ¶m);
|
||||
set_read_value(&gattc_if, ¶m, &arg->read);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_CHAR_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_WRITE_CHAR_EVT:
|
||||
case BTA_GATTC_PREP_WRITE_EVT: {
|
||||
tBTA_GATTC_WRITE *write = &arg->write;
|
||||
uint32_t ret_evt = (msg->act == BTA_GATTC_WRITE_CHAR_EVT) ?
|
||||
ESP_GATTC_WRITE_CHAR_EVT : ESP_GATTC_PREP_WRITE_EVT;
|
||||
param.write.conn_id = write->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(write->conn_id);
|
||||
param.write.conn_id = BTC_GATT_GET_CONN_ID(write->conn_id);
|
||||
param.write.status = write->status;
|
||||
bta_to_btc_srvc_id(¶m.write.srvc_id, &write->srvc_id);
|
||||
bta_to_btc_gatt_id(¶m.write.char_id, &write->char_id);
|
||||
BTC_GATTC_CB_TO_APP(ret_evt, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ret_evt, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_EXEC_EVT: {
|
||||
tBTA_GATTC_EXEC_CMPL *exec_cmpl = &arg->exec_cmpl;
|
||||
param.exec_cmpl.conn_id = exec_cmpl->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(exec_cmpl->conn_id);
|
||||
param.exec_cmpl.conn_id = BTC_GATT_GET_CONN_ID(exec_cmpl->conn_id);
|
||||
param.exec_cmpl.status = exec_cmpl->status;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_EXEC_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_EXEC_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_SEARCH_CMPL_EVT: {
|
||||
tBTA_GATTC_SEARCH_CMPL *search_cmpl = &arg->search_cmpl;
|
||||
param.search_cmpl.conn_id = search_cmpl->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(search_cmpl->conn_id);
|
||||
param.search_cmpl.conn_id = BTC_GATT_GET_CONN_ID(search_cmpl->conn_id);
|
||||
param.search_cmpl.status = search_cmpl->status;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_CMPL_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_CMPL_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_SEARCH_RES_EVT: {
|
||||
tBTA_GATTC_SRVC_RES *srvc_res = &arg->srvc_res;
|
||||
param.search_res.conn_id = srvc_res->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(srvc_res->conn_id);
|
||||
param.search_res.conn_id = BTC_GATT_GET_CONN_ID(srvc_res->conn_id);
|
||||
bta_to_btc_srvc_id(¶m.search_res.srvc_id, &srvc_res->service_uuid);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_RES_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_RES_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_READ_DESCR_EVT: {
|
||||
set_read_value(¶m, &arg->read);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_DESCR_EVT, ¶m);
|
||||
set_read_value(&gattc_if, ¶m, &arg->read);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_DESCR_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_WRITE_DESCR_EVT: {
|
||||
tBTA_GATTC_WRITE *write = &arg->write;
|
||||
param.write.conn_id = write->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(write->conn_id);
|
||||
param.write.conn_id = BTC_GATT_GET_CONN_ID(write->conn_id);
|
||||
param.write.status = write->status;
|
||||
bta_to_btc_srvc_id(¶m.write.srvc_id, &write->srvc_id);
|
||||
bta_to_btc_gatt_id(¶m.write.char_id, &write->char_id);
|
||||
bta_to_btc_gatt_id(¶m.write.descr_id, &write->descr_type);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_WRITE_DESCR_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_WRITE_DESCR_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_NOTIF_EVT: {
|
||||
tBTA_GATTC_NOTIFY *notify = &arg->notify;
|
||||
param.notify.conn_id = notify->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(notify->conn_id);
|
||||
param.notify.conn_id = BTC_GATT_GET_CONN_ID(notify->conn_id);
|
||||
memcpy(param.notify.remote_bda, notify->bda, sizeof(esp_bd_addr_t));
|
||||
bta_to_btc_srvc_id(¶m.notify.srvc_id, ¬ify->char_id.srvc_id);
|
||||
bta_to_btc_gatt_id(¶m.notify.char_id, ¬ify->char_id.char_id);
|
||||
@ -597,57 +626,63 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
|
||||
BTA_GATTC_SendIndConfirm(notify->conn_id, ¬ify->char_id);
|
||||
}
|
||||
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_NOTIFY_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_NOTIFY_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_OPEN_EVT: {
|
||||
tBTA_GATTC_OPEN *open = &arg->open;
|
||||
|
||||
gattc_if = open->client_if;
|
||||
param.open.status = open->status;
|
||||
param.open.conn_id = open->conn_id;
|
||||
param.open.gatt_if = open->client_if;
|
||||
param.open.conn_id = BTC_GATT_GET_CONN_ID(open->conn_id);
|
||||
memcpy(param.open.remote_bda, open->remote_bda, sizeof(esp_bd_addr_t));
|
||||
param.open.mtu = open->mtu;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_OPEN_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_OPEN_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_CLOSE_EVT: {
|
||||
tBTA_GATTC_CLOSE *close = &arg->close;
|
||||
|
||||
gattc_if = close->client_if;
|
||||
param.close.status = close->status;
|
||||
param.close.conn_id = close->conn_id;
|
||||
param.close.gatt_if = close->client_if;
|
||||
param.close.conn_id = BTC_GATT_GET_CONN_ID(close->conn_id);
|
||||
memcpy(param.close.remote_bda, close->remote_bda, sizeof(esp_bd_addr_t));
|
||||
param.close.reason = close->reason;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CLOSE_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CLOSE_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_CFG_MTU_EVT: {
|
||||
tBTA_GATTC_CFG_MTU *cfg_mtu = &arg->cfg_mtu;
|
||||
param.cfg_mtu.conn_id = cfg_mtu->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(cfg_mtu->conn_id);
|
||||
param.cfg_mtu.conn_id = BTC_GATT_GET_CONN_ID(cfg_mtu->conn_id);
|
||||
param.cfg_mtu.status = cfg_mtu->status;
|
||||
param.cfg_mtu.mtu = cfg_mtu->mtu;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CFG_MTU_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CFG_MTU_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_ACL_EVT: {
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_ACL_EVT, NULL);
|
||||
/* Currently, this event will never happen */
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_CANCEL_OPEN_EVT: {
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CANCEL_OPEN_EVT, NULL);
|
||||
/* Currently, this event will never happen */
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_CONGEST_EVT: {
|
||||
tBTA_GATTC_CONGEST *congest = &arg->congest;
|
||||
param.congest.conn_id = congest->conn_id;
|
||||
|
||||
gattc_if = BTC_GATT_GET_GATT_IF(congest->conn_id);
|
||||
param.congest.conn_id = BTC_GATT_GET_CONN_ID(congest->conn_id);
|
||||
param.congest.congested = (congest->congested == TRUE) ? true : false;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CONGEST_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CONGEST_EVT, gattc_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_SRVC_CHG_EVT: {
|
||||
memcpy(param.srvc_chg.remote_bda, arg->remote_bda, sizeof(esp_bd_addr_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SRVC_CHG_EVT, ¶m);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SRVC_CHG_EVT, ESP_GATT_IF_NONE, ¶m);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "esp_gatts_api.h"
|
||||
|
||||
#define BTC_GATTS_CB_TO_APP(_event, _param) ((esp_profile_cb_t)btc_profile_cb_get(BTC_PID_GATTS))(_event, _param)
|
||||
#define BTC_GATTS_CB_TO_APP(event, gatts_if, param) ((esp_gatts_cb_t)btc_profile_cb_get(BTC_PID_GATTS))((event), (gatts_if), (param))
|
||||
|
||||
#define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT
|
||||
#define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT
|
||||
@ -171,12 +171,12 @@ void btc_gatts_call_handler(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_APP_UNREGISTER:
|
||||
BTA_GATTS_AppDeregister(arg->app_unreg.gatt_if);
|
||||
BTA_GATTS_AppDeregister(arg->app_unreg.gatts_if);
|
||||
break;
|
||||
case BTC_GATTS_ACT_CREATE_SERVICE: {
|
||||
tBTA_GATT_SRVC_ID srvc_id;
|
||||
btc_to_bta_srvc_id(&srvc_id, &arg->create_srvc.service_id);
|
||||
BTA_GATTS_CreateService(arg->create_srvc.gatt_if, &srvc_id.id.uuid,
|
||||
BTA_GATTS_CreateService(arg->create_srvc.gatts_if, &srvc_id.id.uuid,
|
||||
srvc_id.id.inst_id, arg->create_srvc.num_handle,
|
||||
srvc_id.is_primary);
|
||||
break;
|
||||
@ -227,7 +227,7 @@ void btc_gatts_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
|
||||
param.rsp.status = 0;
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_RESPONSE_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_RESPONSE_EVT, BTC_GATT_GET_GATT_IF(arg->send_rsp.conn_id), ¶m);
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_OPEN: {
|
||||
@ -252,7 +252,7 @@ void btc_gatts_call_handler(btc_msg_t *msg)
|
||||
transport = BTA_GATT_TRANSPORT_LE;
|
||||
|
||||
// Connect!
|
||||
BTA_GATTS_Open(arg->open.gatt_if, arg->open.remote_bda,
|
||||
BTA_GATTS_Open(arg->open.gatts_if, arg->open.remote_bda,
|
||||
arg->open.is_direct, transport);
|
||||
break;
|
||||
}
|
||||
@ -277,34 +277,38 @@ void btc_gatts_call_handler(btc_msg_t *msg)
|
||||
void btc_gatts_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_gatts_cb_param_t param;
|
||||
|
||||
tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg;
|
||||
esp_gatt_if_t gatts_if;
|
||||
|
||||
switch (msg->act) {
|
||||
case BTA_GATTS_REG_EVT: {
|
||||
gatts_if = p_data->reg_oper.server_if;
|
||||
param.reg.status = p_data->reg_oper.status;
|
||||
param.reg.gatt_if = p_data->reg_oper.server_if;
|
||||
param.reg.app_id = p_data->reg_oper.uuid.uu.uuid16;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_REG_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_REG_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_DEREG_EVT:
|
||||
// do nothing
|
||||
case BTA_GATTS_DEREG_EVT: {
|
||||
gatts_if = p_data->reg_oper.server_if;
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_UNREG_EVT, gatts_if, NULL);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_READ_EVT: {
|
||||
param.read.conn_id = p_data->req_data.conn_id;
|
||||
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
|
||||
param.read.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
|
||||
param.read.trans_id = p_data->req_data.trans_id;
|
||||
memcpy(param.read.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
|
||||
param.read.handle = p_data->req_data.p_data->read_req.handle,
|
||||
param.read.offset = p_data->req_data.p_data->read_req.offset,
|
||||
param.read.is_long = p_data->req_data.p_data->read_req.is_long,
|
||||
param.read.offset = p_data->req_data.p_data->read_req.offset,
|
||||
param.read.is_long = p_data->req_data.p_data->read_req.is_long,
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_READ_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_READ_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_WRITE_EVT: {
|
||||
param.write.conn_id = p_data->req_data.conn_id;
|
||||
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
|
||||
param.write.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
|
||||
param.write.trans_id = p_data->req_data.trans_id;
|
||||
memcpy(param.write.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
|
||||
param.write.handle = p_data->req_data.p_data->write_req.handle;
|
||||
@ -314,103 +318,104 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
|
||||
param.write.len = p_data->req_data.p_data->write_req.len;
|
||||
param.write.value = p_data->req_data.p_data->write_req.value;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_WRITE_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_WRITE_EVT, gatts_if, ¶m);
|
||||
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_EXEC_WRITE_EVT: {
|
||||
param.exec_write.conn_id = p_data->req_data.conn_id;
|
||||
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
|
||||
param.exec_write.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
|
||||
param.exec_write.trans_id = p_data->req_data.trans_id;
|
||||
memcpy(param.exec_write.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
|
||||
param.exec_write.exec_write_flag = p_data->req_data.p_data->exec_write;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_EXEC_WRITE_EVT, ¶m);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_EXEC_WRITE_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_MTU_EVT:
|
||||
param.mtu.conn_id = p_data->req_data.conn_id;
|
||||
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
|
||||
param.mtu.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
|
||||
param.mtu.mtu = p_data->req_data.p_data->mtu;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_MTU_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_MTU_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_CONF_EVT:
|
||||
param.conf.conn_id = p_data->req_data.conn_id;
|
||||
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
|
||||
param.conf.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
|
||||
param.conf.status = p_data->req_data.status;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONF_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONF_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_CREATE_EVT:
|
||||
gatts_if = p_data->create.server_if;
|
||||
param.create.status = p_data->create.status;
|
||||
param.create.gatt_if = p_data->create.server_if;
|
||||
param.create.service_handle = p_data->create.service_id;
|
||||
param.create.service_id.is_primary = p_data->create.is_primary;
|
||||
param.create.service_id.id.inst_id = p_data->create.svc_instance;
|
||||
bta_to_btc_uuid(¶m.create.service_id.id.uuid, &p_data->create.uuid);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_ADD_INCL_SRVC_EVT:
|
||||
gatts_if = p_data->add_result.server_if;
|
||||
param.add_incl_srvc.status = p_data->add_result.status;
|
||||
param.add_incl_srvc.gatt_if = p_data->add_result.server_if;
|
||||
param.add_incl_srvc.attr_handle = p_data->add_result.attr_id;
|
||||
param.add_incl_srvc.service_handle = p_data->add_result.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_INCL_SRVC_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_INCL_SRVC_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_ADD_CHAR_EVT:
|
||||
gatts_if = p_data->add_result.server_if;
|
||||
param.add_char.status = p_data->add_result.status;
|
||||
param.add_char.gatt_if = p_data->add_result.server_if;
|
||||
param.add_char.attr_handle = p_data->add_result.attr_id;
|
||||
param.add_char.service_handle = p_data->add_result.service_id;
|
||||
bta_to_btc_uuid(¶m.add_char.char_uuid, &p_data->add_result.char_uuid);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
|
||||
gatts_if = p_data->add_result.server_if;
|
||||
param.add_char_descr.status = p_data->add_result.status;
|
||||
param.add_char_descr.gatt_if = p_data->add_result.server_if;
|
||||
param.add_char_descr.attr_handle = p_data->add_result.attr_id;
|
||||
param.add_char_descr.service_handle = p_data->add_result.service_id;
|
||||
bta_to_btc_uuid(¶m.add_char_descr.char_uuid, &p_data->add_result.char_uuid);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_DESCR_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_DESCR_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_DELELTE_EVT:
|
||||
gatts_if = p_data->srvc_oper.server_if;
|
||||
param.del.status = p_data->srvc_oper.status;
|
||||
param.del.gatt_if = p_data->srvc_oper.server_if;
|
||||
param.del.service_handle = p_data->srvc_oper.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELETE_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELETE_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_START_EVT:
|
||||
gatts_if = p_data->srvc_oper.server_if;
|
||||
param.start.status = p_data->srvc_oper.status;
|
||||
param.start.gatt_if = p_data->srvc_oper.server_if;
|
||||
param.start.service_handle = p_data->srvc_oper.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_START_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_START_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_STOP_EVT:
|
||||
gatts_if = p_data->srvc_oper.server_if;
|
||||
param.stop.status = p_data->srvc_oper.status;
|
||||
param.stop.gatt_if = p_data->srvc_oper.server_if;
|
||||
param.stop.service_handle = p_data->srvc_oper.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_STOP_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_STOP_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_CONNECT_EVT:
|
||||
param.connect.conn_id = p_data->conn.conn_id;
|
||||
param.connect.gatt_if = p_data->conn.server_if;
|
||||
gatts_if = p_data->conn.server_if;
|
||||
param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
|
||||
param.connect.is_connected = true;
|
||||
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONNECT_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONNECT_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_DISCONNECT_EVT:
|
||||
param.connect.conn_id = p_data->conn.conn_id;
|
||||
param.connect.gatt_if = p_data->conn.server_if;
|
||||
param.connect.is_connected = false;
|
||||
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
|
||||
gatts_if = p_data->conn.server_if;
|
||||
param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
|
||||
param.disconnect.is_connected = false;
|
||||
memcpy(param.disconnect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DISCONNECT_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DISCONNECT_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_OPEN_EVT:
|
||||
// do nothing
|
||||
@ -422,8 +427,10 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
|
||||
// do nothing
|
||||
break;
|
||||
case BTA_GATTS_CONGEST_EVT:
|
||||
param.congest.conn_id = p_data->congest.conn_id;
|
||||
gatts_if = BTC_GATT_GET_GATT_IF(p_data->congest.conn_id);
|
||||
param.congest.conn_id = BTC_GATT_GET_CONN_ID(p_data->congest.conn_id);
|
||||
param.congest.congested = p_data->congest.congested;
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONGEST_EVT, gatts_if, ¶m);
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
|
@ -21,6 +21,10 @@
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_gattc_api.h"
|
||||
|
||||
#define BTC_GATT_CREATE_CONN_ID(gatt_if, conn_id) ((uint16_t) ((((uint8_t)(conn_id)) << 8) | ((uint8_t)(gatt_if))))
|
||||
#define BTC_GATT_GET_CONN_ID(conn_id) (((uint16_t)(conn_id)) >> 8)
|
||||
#define BTC_GATT_GET_GATT_IF(conn_id) ((uint8_t)(conn_id))
|
||||
|
||||
void 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);
|
||||
@ -31,6 +35,6 @@ void bta_to_btc_uuid(esp_bt_uuid_t *p_dest, tBT_UUID *p_src);
|
||||
void bta_to_btc_gatt_id(esp_gatt_id_t *p_dest, tBTA_GATT_ID *p_src);
|
||||
void bta_to_btc_srvc_id(esp_gatt_srvc_id_t *p_dest, tBTA_GATT_SRVC_ID *p_src);
|
||||
|
||||
uint16_t set_read_value(esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src);
|
||||
uint16_t set_read_value(uint8_t *gattc_if, esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src);
|
||||
|
||||
#endif /* __BTC_GATT_UTIL_H__*/
|
@ -51,11 +51,11 @@ typedef union {
|
||||
} app_reg;
|
||||
//BTC_GATTC_ACT_APP_UNREGISTER,
|
||||
struct app_unreg_arg {
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_gatt_if_t gattc_if;
|
||||
} app_unreg;
|
||||
//BTC_GATTC_ACT_OPEN,
|
||||
struct open_arg {
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_gatt_if_t gattc_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
bool is_direct;
|
||||
} open;
|
||||
@ -162,14 +162,14 @@ typedef union {
|
||||
} exec_write;
|
||||
//BTC_GATTC_ACT_REG_FOR_NOTIFY,
|
||||
struct reg_for_notify_arg {
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_gatt_if_t gattc_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
esp_gatt_srvc_id_t service_id;
|
||||
esp_gatt_id_t char_id;
|
||||
} reg_for_notify;
|
||||
//BTC_GATTC_ACT_UNREG_FOR_NOTIFY
|
||||
struct unreg_for_notify_arg {
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_gatt_if_t gattc_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
esp_gatt_srvc_id_t service_id;
|
||||
esp_gatt_id_t char_id;
|
||||
|
@ -44,11 +44,11 @@ typedef union {
|
||||
} app_reg;
|
||||
//BTC_GATTS_ACT_APP_UNREGISTER,
|
||||
struct app_unreg_args {
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_gatt_if_t gatts_if;
|
||||
} app_unreg;
|
||||
//BTC_GATTS_ACT_CREATE_SERVICE,
|
||||
struct create_srvc_args {
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_gatt_if_t gatts_if;
|
||||
esp_gatt_srvc_id_t service_id;
|
||||
uint16_t num_handle;
|
||||
} create_srvc;
|
||||
@ -99,7 +99,7 @@ typedef union {
|
||||
} send_rsp;
|
||||
//BTC_GATTS_ACT_OPEN,
|
||||
struct open_args {
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_gatt_if_t gatts_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
bool is_direct;
|
||||
} open;
|
||||
|
@ -40,7 +40,6 @@ Type Definitions
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygentypedef:: esp_bd_addr_t
|
||||
.. doxygentypedef:: esp_profile_cb_t
|
||||
|
||||
Enumerations
|
||||
^^^^^^^^^^^^
|
||||
|
@ -38,6 +38,7 @@ Macros
|
||||
Type Definitions
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygentypedef:: esp_gap_ble_cb_t
|
||||
|
||||
Enumerations
|
||||
^^^^^^^^^^^^
|
||||
|
@ -85,6 +85,7 @@ Macros
|
||||
.. doxygendefine:: ESP_GATT_UUID_SCAN_REFRESH
|
||||
.. doxygendefine:: ESP_GATT_ILLEGAL_UUID
|
||||
.. doxygendefine:: ESP_GATT_MAX_ATTR_LEN
|
||||
.. doxygendefine:: ESP_GATT_IF_NONE
|
||||
|
||||
Type Definitions
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
@ -37,6 +37,7 @@ Macros
|
||||
Type Definitions
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygentypedef:: esp_gattc_cb_t
|
||||
|
||||
Enumerations
|
||||
^^^^^^^^^^^^
|
||||
|
@ -37,6 +37,7 @@ Macros
|
||||
Type Definitions
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. doxygentypedef:: esp_gatts_cb_t
|
||||
|
||||
Enumerations
|
||||
^^^^^^^^^^^^
|
||||
|
@ -70,7 +70,7 @@ static void blufi_data_recv(uint8_t *data, int len)
|
||||
|
||||
}
|
||||
|
||||
static void blufi_callback(uint32_t event, void *param)
|
||||
static void blufi_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param)
|
||||
{
|
||||
/* actually, should post to blufi_task handle the procedure,
|
||||
* now, as a demo, we do simplely */
|
||||
@ -91,11 +91,6 @@ static void blufi_callback(uint32_t event, void *param)
|
||||
|
||||
static esp_err_t blufi_startup_in_blufi_task(void *arg)
|
||||
{
|
||||
/*set connectable,discoverable, pairable and paired only modes of local device*/
|
||||
tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
|
||||
tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
|
||||
BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL);
|
||||
|
||||
esp_blufi_register_callback(blufi_callback);
|
||||
esp_blufi_profile_init();
|
||||
|
||||
@ -112,8 +107,6 @@ esp_err_t blufi_enable(void *arg)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
BTM_SetTraceLevel(BT_TRACE_LEVEL_ERROR);
|
||||
|
||||
err = esp_enable_bluetooth();
|
||||
if (err) {
|
||||
LOG_ERROR("%s failed\n", __func__);
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// You may obtain A copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
@ -30,13 +30,21 @@
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#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 "ESP_GATTS_DEMO"
|
||||
///Declare the static function
|
||||
static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
|
||||
static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
|
||||
|
||||
#define GATTS_SERVICE_UUID_TEST_A 0x00FF
|
||||
#define GATTS_CHAR_UUID_TEST_A 0xFF01
|
||||
#define GATTS_DESCR_UUID_TEST_A 0x3333
|
||||
#define GATTS_NUM_HANDLE_TEST_A 4
|
||||
|
||||
#define GATTS_SERVICE_UUID_TEST_B 0x00EE
|
||||
#define GATTS_CHAR_UUID_TEST_B 0xEE01
|
||||
#define GATTS_DESCR_UUID_TEST_B 0x2222
|
||||
#define GATTS_NUM_HANDLE_TEST_B 4
|
||||
|
||||
#define TEST_DEVICE_NAME "ESP_GATTS_DEMO"
|
||||
#define TEST_MANUFACTURER_DATA_LEN 17
|
||||
static uint8_t test_service_uuid128[32] = {
|
||||
/* LSB <--------------------------------------------------------------------------------> MSB */
|
||||
@ -74,8 +82,13 @@ static esp_ble_adv_params_t test_adv_params = {
|
||||
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
|
||||
};
|
||||
|
||||
struct gatts_test_inst {
|
||||
uint16_t gatt_if;
|
||||
#define PROFILE_NUM 2
|
||||
#define PROFILE_A_APP_ID 0
|
||||
#define PROFILE_B_APP_ID 1
|
||||
|
||||
struct gatts_profile_inst {
|
||||
esp_gatts_cb_t gatts_cb;
|
||||
uint16_t gatts_if;
|
||||
uint16_t app_id;
|
||||
uint16_t conn_id;
|
||||
uint16_t service_handle;
|
||||
@ -87,9 +100,20 @@ struct gatts_test_inst {
|
||||
uint16_t descr_handle;
|
||||
esp_bt_uuid_t descr_uuid;
|
||||
};
|
||||
static struct gatts_test_inst gl_test;
|
||||
|
||||
static void gap_event_handler(uint32_t event, void *param)
|
||||
/* One gatt-based profile one app_id and one gatts_if, this array will store the gatts_if returned by ESP_GATTS_REG_EVT */
|
||||
static struct gatts_profile_inst gl_profile_tab[PROFILE_NUM] = {
|
||||
[PROFILE_A_APP_ID] = {
|
||||
.gatts_cb = gatts_profile_a_event_handler,
|
||||
.gatts_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
|
||||
},
|
||||
[PROFILE_B_APP_ID] = {
|
||||
.gatts_cb = gatts_profile_b_event_handler, /* This demo does not implement, similar as profile A */
|
||||
.gatts_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
|
||||
},
|
||||
};
|
||||
|
||||
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
|
||||
{
|
||||
LOG_ERROR("GAP_EVT, event %d\n", event);
|
||||
|
||||
@ -102,42 +126,42 @@ static void gap_event_handler(uint32_t event, void *param)
|
||||
}
|
||||
}
|
||||
|
||||
static void gatts_event_handler(uint32_t event, void *param)
|
||||
{
|
||||
esp_ble_gatts_cb_param_t *p = (esp_ble_gatts_cb_param_t *)param;
|
||||
|
||||
static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
LOG_INFO("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 = 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;
|
||||
LOG_INFO("REGISTER_APP_EVT, status %d, app_id %d\n", param->reg.status, param->reg.app_id);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.is_primary = true;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.inst_id = 0x00;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
|
||||
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
esp_ble_gap_config_adv_data(&test_adv_data);
|
||||
|
||||
esp_ble_gatts_create_service(gl_test.gatt_if, &gl_test.service_id, GATTS_NUM_HANDLE_TEST);
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_A_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_A);
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
break;
|
||||
case ESP_GATTS_READ_EVT: {
|
||||
LOG_INFO("GATT_READ_EVT, conn_id %d, trans_id %d, handle %d\n", p->read.conn_id, p->read.trans_id, p->read.handle);
|
||||
LOG_INFO("GATT_READ_EVT, conn_id %d, trans_id %d, handle %d\n", param->read.conn_id, param->read.trans_id, param->read.handle);
|
||||
esp_gatt_rsp_t rsp;
|
||||
memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
|
||||
rsp.attr_value.handle = p->read.handle;
|
||||
rsp.attr_value.handle = param->read.handle;
|
||||
rsp.attr_value.len = 4;
|
||||
rsp.attr_value.value[0] = 0xde;
|
||||
rsp.attr_value.value[1] = 0xed;
|
||||
rsp.attr_value.value[2] = 0xbe;
|
||||
rsp.attr_value.value[3] = 0xef;
|
||||
esp_ble_gatts_send_response(p->read.conn_id, p->read.trans_id,
|
||||
esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
|
||||
ESP_GATT_OK, &rsp);
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_WRITE_EVT: {
|
||||
LOG_INFO("GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d\n", p->write.conn_id, p->write.trans_id, p->write.handle);
|
||||
LOG_INFO("GATT_WRITE_EVT, value len %d, value %08x\n", p->write.len, *(uint32_t *)p->write.value);
|
||||
esp_ble_gatts_send_response(p->write.conn_id, p->write.trans_id, ESP_GATT_OK, NULL);
|
||||
LOG_INFO("GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d\n", param->write.conn_id, param->write.trans_id, param->write.handle);
|
||||
LOG_INFO("GATT_WRITE_EVT, value len %d, value %08x\n", param->write.len, *(uint32_t *)param->write.value);
|
||||
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL);
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_EXEC_WRITE_EVT:
|
||||
@ -146,48 +170,48 @@ static void gatts_event_handler(uint32_t event, void *param)
|
||||
case ESP_GATTS_UNREG_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CREATE_EVT:
|
||||
LOG_INFO("CREATE_SERVICE_EVT, status %d, gatt_if %d, service_handle %d\n", p->create.status, p->create.gatt_if, p->create.service_handle);
|
||||
gl_test.service_handle = p->create.service_handle;
|
||||
gl_test.char_uuid.len = ESP_UUID_LEN_16;
|
||||
gl_test.char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST;
|
||||
LOG_INFO("CREATE_SERVICE_EVT, status %d, service_handle %d\n", param->create.status, param->create.service_handle);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_handle = param->create.service_handle;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_A;
|
||||
|
||||
esp_ble_gatts_start_service(gl_test.service_handle);
|
||||
esp_ble_gatts_start_service(gl_profile_tab[PROFILE_A_APP_ID].service_handle);
|
||||
|
||||
esp_ble_gatts_add_char(gl_test.service_handle, &gl_test.char_uuid,
|
||||
esp_ble_gatts_add_char(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].char_uuid,
|
||||
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
|
||||
ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
break;
|
||||
case ESP_GATTS_ADD_INCL_SRVC_EVT:
|
||||
break;
|
||||
case ESP_GATTS_ADD_CHAR_EVT:
|
||||
LOG_INFO("ADD_CHAR_EVT, status %d, gatt_if %d, attr_handle %d, service_handle %d\n",
|
||||
p->add_char.status, p->add_char.gatt_if, p->add_char.attr_handle, p->add_char.service_handle);
|
||||
LOG_INFO("ADD_CHAR_EVT, status %d, attr_handle %d, service_handle %d\n",
|
||||
param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle);
|
||||
|
||||
gl_test.char_handle = p->add_char.attr_handle;
|
||||
gl_test.descr_uuid.len = ESP_UUID_LEN_16;
|
||||
gl_test.descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
|
||||
esp_ble_gatts_add_char_descr(gl_test.service_handle, &gl_test.descr_uuid,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_handle = param->add_char.attr_handle;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
|
||||
esp_ble_gatts_add_char_descr(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].descr_uuid,
|
||||
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
|
||||
break;
|
||||
case ESP_GATTS_ADD_CHAR_DESCR_EVT:
|
||||
LOG_INFO("ADD_DESCR_EVT, status %d, gatt_if %d, attr_handle %d, service_handle %d\n",
|
||||
p->add_char.status, p->add_char.gatt_if, p->add_char.attr_handle, p->add_char.service_handle);
|
||||
LOG_INFO("ADD_DESCR_EVT, status %d, attr_handle %d, service_handle %d\n",
|
||||
param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle);
|
||||
break;
|
||||
case ESP_GATTS_DELETE_EVT:
|
||||
break;
|
||||
case ESP_GATTS_START_EVT:
|
||||
LOG_INFO("SERVICE_START_EVT, status %d, gatt_if %d, service_handle %d\n",
|
||||
p->start.status, p->start.gatt_if, p->start.service_handle);
|
||||
LOG_INFO("SERVICE_START_EVT, status %d, service_handle %d\n",
|
||||
param->start.status, param->start.service_handle);
|
||||
break;
|
||||
case ESP_GATTS_STOP_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CONNECT_EVT:
|
||||
LOG_INFO("SERVICE_START_EVT, conn_id %d, gatt_if %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d\n",
|
||||
p->connect.conn_id, p->connect.gatt_if,
|
||||
p->connect.remote_bda[0], p->connect.remote_bda[1], p->connect.remote_bda[2],
|
||||
p->connect.remote_bda[3], p->connect.remote_bda[4], p->connect.remote_bda[5],
|
||||
p->connect.is_connected);
|
||||
gl_test.conn_id = p->connect.conn_id;
|
||||
LOG_INFO("SERVICE_START_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d\n",
|
||||
param->connect.conn_id,
|
||||
param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2],
|
||||
param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5],
|
||||
param->connect.is_connected);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id = param->connect.conn_id;
|
||||
break;
|
||||
case ESP_GATTS_DISCONNECT_EVT:
|
||||
case ESP_GATTS_OPEN_EVT:
|
||||
@ -200,6 +224,135 @@ static void gatts_event_handler(uint32_t event, void *param)
|
||||
}
|
||||
}
|
||||
|
||||
static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
LOG_INFO("REGISTER_APP_EVT, status %d, app_id %d\n", param->reg.status, param->reg.app_id);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.is_primary = true;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.inst_id = 0x00;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_B;
|
||||
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
esp_ble_gap_config_adv_data(&test_adv_data);
|
||||
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_A_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_B);
|
||||
LOG_INFO("%s %d\n", __func__, __LINE__);
|
||||
break;
|
||||
case ESP_GATTS_READ_EVT: {
|
||||
LOG_INFO("GATT_READ_EVT, conn_id %d, trans_id %d, handle %d\n", param->read.conn_id, param->read.trans_id, param->read.handle);
|
||||
esp_gatt_rsp_t rsp;
|
||||
memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
|
||||
rsp.attr_value.handle = param->read.handle;
|
||||
rsp.attr_value.len = 4;
|
||||
rsp.attr_value.value[0] = 0xde;
|
||||
rsp.attr_value.value[1] = 0xed;
|
||||
rsp.attr_value.value[2] = 0xbe;
|
||||
rsp.attr_value.value[3] = 0xef;
|
||||
esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
|
||||
ESP_GATT_OK, &rsp);
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_WRITE_EVT: {
|
||||
LOG_INFO("GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d\n", param->write.conn_id, param->write.trans_id, param->write.handle);
|
||||
LOG_INFO("GATT_WRITE_EVT, value len %d, value %08x\n", param->write.len, *(uint32_t *)param->write.value);
|
||||
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL);
|
||||
break;
|
||||
}
|
||||
case ESP_GATTS_EXEC_WRITE_EVT:
|
||||
case ESP_GATTS_MTU_EVT:
|
||||
case ESP_GATTS_CONF_EVT:
|
||||
case ESP_GATTS_UNREG_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CREATE_EVT:
|
||||
LOG_INFO("CREATE_SERVICE_EVT, status %d, service_handle %d\n", param->create.status, param->create.service_handle);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_handle = param->create.service_handle;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_B;
|
||||
|
||||
esp_ble_gatts_start_service(gl_profile_tab[PROFILE_A_APP_ID].service_handle);
|
||||
|
||||
esp_ble_gatts_add_char(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].char_uuid,
|
||||
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
|
||||
ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
break;
|
||||
case ESP_GATTS_ADD_INCL_SRVC_EVT:
|
||||
break;
|
||||
case ESP_GATTS_ADD_CHAR_EVT:
|
||||
LOG_INFO("ADD_CHAR_EVT, status %d, attr_handle %d, service_handle %d\n",
|
||||
param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle);
|
||||
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_handle = param->add_char.attr_handle;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
|
||||
esp_ble_gatts_add_char_descr(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].descr_uuid,
|
||||
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE);
|
||||
break;
|
||||
case ESP_GATTS_ADD_CHAR_DESCR_EVT:
|
||||
LOG_INFO("ADD_DESCR_EVT, status %d, attr_handle %d, service_handle %d\n",
|
||||
param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle);
|
||||
break;
|
||||
case ESP_GATTS_DELETE_EVT:
|
||||
break;
|
||||
case ESP_GATTS_START_EVT:
|
||||
LOG_INFO("SERVICE_START_EVT, status %d, service_handle %d\n",
|
||||
param->start.status, param->start.service_handle);
|
||||
break;
|
||||
case ESP_GATTS_STOP_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CONNECT_EVT:
|
||||
LOG_INFO("SERVICE_START_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d\n",
|
||||
param->connect.conn_id,
|
||||
param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2],
|
||||
param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5],
|
||||
param->connect.is_connected);
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id = param->connect.conn_id;
|
||||
break;
|
||||
case ESP_GATTS_DISCONNECT_EVT:
|
||||
case ESP_GATTS_OPEN_EVT:
|
||||
case ESP_GATTS_CANCEL_OPEN_EVT:
|
||||
case ESP_GATTS_CLOSE_EVT:
|
||||
case ESP_GATTS_LISTEN_EVT:
|
||||
case ESP_GATTS_CONGEST_EVT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
|
||||
{
|
||||
LOG_INFO("EVT %d, gatts if %d\n", event, gatts_if);
|
||||
|
||||
/* If event is register event, store the gatts_if for each profile */
|
||||
if (event == ESP_GATTS_REG_EVT) {
|
||||
if (param->reg.status == ESP_GATT_OK) {
|
||||
gl_profile_tab[param->reg.app_id].gatts_if = gatts_if;
|
||||
} else {
|
||||
LOG_INFO("Reg app failed, app_id %04x, status %d\n",
|
||||
param->reg.app_id,
|
||||
param->reg.status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the gatts_if equal to profile A, call profile A cb handler,
|
||||
* so here call each profile's callback */
|
||||
do {
|
||||
int idx;
|
||||
for (idx = 0; idx < PROFILE_NUM; idx++) {
|
||||
if (gatts_if == ESP_GATT_IF_NONE || /* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */
|
||||
gatts_if == gl_profile_tab[idx].gatts_if) {
|
||||
if (gl_profile_tab[idx].gatts_cb) {
|
||||
gl_profile_tab[idx].gatts_cb(event, gatts_if, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_err_t ret;
|
||||
@ -219,7 +372,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(GATTS_SERVICE_UUID_TEST);
|
||||
esp_ble_gatts_app_register(PROFILE_A_APP_ID);
|
||||
esp_ble_gatts_app_register(PROFILE_B_APP_ID);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -37,16 +37,36 @@
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
///Declare static functions
|
||||
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
|
||||
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
|
||||
|
||||
static esp_gatt_srvc_id_t alert_service_id = {
|
||||
.id = {
|
||||
.uuid = {
|
||||
.len = ESP_UUID_LEN_16,
|
||||
.uuid = {.uuid16 = 0x1811,},
|
||||
},
|
||||
.inst_id = 0,
|
||||
},
|
||||
.is_primary = true,
|
||||
};
|
||||
|
||||
static esp_gatt_id_t notify_descr_id = {
|
||||
.uuid = {
|
||||
.len = ESP_UUID_LEN_16,
|
||||
.uuid = {.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG,},
|
||||
},
|
||||
.inst_id = 0,
|
||||
};
|
||||
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
||||
|
||||
esp_gatt_if_t client_if;
|
||||
esp_gatt_status_t status = ESP_GATT_ERROR;
|
||||
bool connet = false;
|
||||
uint16_t simpleClient_id = 0xEE;
|
||||
|
||||
const char device_name[] = "Heart Rate";
|
||||
static bool connect = false;
|
||||
static const char device_name[] = "Alert Notification";
|
||||
|
||||
static esp_ble_scan_params_t ble_scan_params = {
|
||||
.scan_type = BLE_SCAN_TYPE_ACTIVE,
|
||||
@ -57,11 +77,213 @@ static esp_ble_scan_params_t ble_scan_params = {
|
||||
};
|
||||
|
||||
|
||||
static void esp_gap_cb(uint32_t event, void *param);
|
||||
#define PROFILE_NUM 2
|
||||
#define PROFILE_A_APP_ID 0
|
||||
#define PROFILE_B_APP_ID 1
|
||||
|
||||
static void esp_gattc_cb(uint32_t event, void *param);
|
||||
struct gattc_profile_inst {
|
||||
esp_gattc_cb_t gattc_cb;
|
||||
uint16_t gattc_if;
|
||||
uint16_t app_id;
|
||||
uint16_t conn_id;
|
||||
esp_bd_addr_t remote_bda;
|
||||
};
|
||||
|
||||
static void esp_gap_cb(uint32_t event, void *param)
|
||||
/* One gatt-based profile one app_id and one gattc_if, this array will store the gattc_if returned by ESP_GATTS_REG_EVT */
|
||||
static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = {
|
||||
[PROFILE_A_APP_ID] = {
|
||||
.gattc_cb = gattc_profile_a_event_handler,
|
||||
.gattc_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
|
||||
},
|
||||
[PROFILE_B_APP_ID] = {
|
||||
.gattc_cb = gattc_profile_b_event_handler,
|
||||
.gattc_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
|
||||
},
|
||||
};
|
||||
|
||||
static void gattc_profile_a_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
|
||||
{
|
||||
uint16_t conn_id = 0;
|
||||
esp_ble_gattc_cb_param_t *p_data = (esp_ble_gattc_cb_param_t *)param;
|
||||
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
LOG_INFO("REG_EVT\n");
|
||||
esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||
break;
|
||||
case ESP_GATTC_OPEN_EVT:
|
||||
conn_id = p_data->open.conn_id;
|
||||
|
||||
memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
||||
LOG_INFO("ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d\n", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
||||
|
||||
LOG_INFO("REMOTE BDA %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[0], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[1],
|
||||
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[2], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[3],
|
||||
gl_profile_tab[PROFILE_A_APP_ID].remote_bda[4], gl_profile_tab[PROFILE_A_APP_ID].remote_bda[5]
|
||||
);
|
||||
|
||||
esp_ble_gattc_search_service(gattc_if, conn_id, NULL);
|
||||
break;
|
||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||
esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id;
|
||||
conn_id = p_data->search_res.conn_id;
|
||||
LOG_INFO("SEARCH RES: conn_id = %x\n", conn_id);
|
||||
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) {
|
||||
LOG_INFO("UUID16: %x\n", srvc_id->id.uuid.uuid.uuid16);
|
||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) {
|
||||
LOG_INFO("UUID32: %x\n", srvc_id->id.uuid.uuid.uuid32);
|
||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
||||
LOG_INFO("UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", srvc_id->id.uuid.uuid.uuid128[0],
|
||||
srvc_id->id.uuid.uuid.uuid128[1], srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3],
|
||||
srvc_id->id.uuid.uuid.uuid128[4], srvc_id->id.uuid.uuid.uuid128[5], srvc_id->id.uuid.uuid.uuid128[6],
|
||||
srvc_id->id.uuid.uuid.uuid128[7], srvc_id->id.uuid.uuid.uuid128[8], srvc_id->id.uuid.uuid.uuid128[9],
|
||||
srvc_id->id.uuid.uuid.uuid128[10], srvc_id->id.uuid.uuid.uuid128[11], srvc_id->id.uuid.uuid.uuid128[12],
|
||||
srvc_id->id.uuid.uuid.uuid128[13], srvc_id->id.uuid.uuid.uuid128[14], srvc_id->id.uuid.uuid.uuid128[15]);
|
||||
} else {
|
||||
LOG_ERROR("UNKNOWN LEN %d\n", srvc_id->id.uuid.len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||
conn_id = p_data->search_cmpl.conn_id;
|
||||
LOG_INFO("SEARCH_CMPL: conn_id = %x, status %d\n", conn_id, p_data->search_cmpl.status);
|
||||
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, NULL);
|
||||
break;
|
||||
case ESP_GATTC_GET_CHAR_EVT:
|
||||
if (p_data->get_char.status != ESP_GATT_OK) {
|
||||
break;
|
||||
}
|
||||
LOG_INFO("GET CHAR: conn_id = %x, status %d\n", p_data->get_char.conn_id, p_data->get_char.status);
|
||||
LOG_INFO("GET CHAR: srvc_id = %04x, char_id = %04x\n", p_data->get_char.srvc_id.id.uuid.uuid.uuid16, p_data->get_char.char_id.uuid.uuid.uuid16);
|
||||
|
||||
if (p_data->get_char.char_id.uuid.uuid.uuid16 == 0x2a46) {
|
||||
LOG_INFO("register notify\n");
|
||||
esp_ble_gattc_register_for_notify(gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, &alert_service_id, &p_data->get_char.char_id);
|
||||
}
|
||||
|
||||
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, &p_data->get_char.char_id);
|
||||
break;
|
||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||
uint16_t notify_en = 1;
|
||||
LOG_INFO("REG FOR NOTIFY: status %d\n", p_data->reg_for_notify.status);
|
||||
LOG_INFO("REG FOR_NOTIFY: srvc_id = %04x, char_id = %04x\n", p_data->reg_for_notify.srvc_id.id.uuid.uuid.uuid16, p_data->reg_for_notify.char_id.uuid.uuid.uuid16);
|
||||
|
||||
esp_ble_gattc_write_char_descr(
|
||||
gattc_if,
|
||||
conn_id,
|
||||
&alert_service_id,
|
||||
&p_data->reg_for_notify.char_id,
|
||||
¬ify_descr_id,
|
||||
sizeof(notify_en),
|
||||
(uint8_t *)¬ify_en,
|
||||
ESP_GATT_WRITE_TYPE_RSP,
|
||||
ESP_GATT_AUTH_REQ_NONE);
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_NOTIFY_EVT:
|
||||
LOG_INFO("NOTIFY: len %d, value %08x\n", p_data->notify.value_len, *(uint32_t *)p_data->notify.value);
|
||||
break;
|
||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
||||
LOG_INFO("WRITE: status %d\n", p_data->write.status);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void gattc_profile_b_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
|
||||
{
|
||||
uint16_t conn_id = 0;
|
||||
esp_ble_gattc_cb_param_t *p_data = (esp_ble_gattc_cb_param_t *)param;
|
||||
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
LOG_INFO("REG_EVT\n");
|
||||
//esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||
break;
|
||||
case ESP_GATTC_OPEN_EVT:
|
||||
conn_id = p_data->open.conn_id;
|
||||
|
||||
memcpy(gl_profile_tab[PROFILE_B_APP_ID].remote_bda, p_data->open.remote_bda, sizeof(esp_bd_addr_t));
|
||||
LOG_INFO("ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d, mtu %d\n", conn_id, gattc_if, p_data->open.status, p_data->open.mtu);
|
||||
|
||||
LOG_INFO("REMOTE BDA %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[0], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[1],
|
||||
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[2], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[3],
|
||||
gl_profile_tab[PROFILE_B_APP_ID].remote_bda[4], gl_profile_tab[PROFILE_B_APP_ID].remote_bda[5]
|
||||
);
|
||||
|
||||
esp_ble_gattc_search_service(gattc_if, conn_id, NULL);
|
||||
break;
|
||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||
esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id;
|
||||
conn_id = p_data->search_res.conn_id;
|
||||
LOG_INFO("SEARCH RES: conn_id = %x\n", conn_id);
|
||||
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) {
|
||||
LOG_INFO("UUID16: %x\n", srvc_id->id.uuid.uuid.uuid16);
|
||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) {
|
||||
LOG_INFO("UUID32: %x\n", srvc_id->id.uuid.uuid.uuid32);
|
||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
||||
LOG_INFO("UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", srvc_id->id.uuid.uuid.uuid128[0],
|
||||
srvc_id->id.uuid.uuid.uuid128[1], srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3],
|
||||
srvc_id->id.uuid.uuid.uuid128[4], srvc_id->id.uuid.uuid.uuid128[5], srvc_id->id.uuid.uuid.uuid128[6],
|
||||
srvc_id->id.uuid.uuid.uuid128[7], srvc_id->id.uuid.uuid.uuid128[8], srvc_id->id.uuid.uuid.uuid128[9],
|
||||
srvc_id->id.uuid.uuid.uuid128[10], srvc_id->id.uuid.uuid.uuid128[11], srvc_id->id.uuid.uuid.uuid128[12],
|
||||
srvc_id->id.uuid.uuid.uuid128[13], srvc_id->id.uuid.uuid.uuid128[14], srvc_id->id.uuid.uuid.uuid128[15]);
|
||||
} else {
|
||||
LOG_ERROR("UNKNOWN LEN %d\n", srvc_id->id.uuid.len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||
conn_id = p_data->search_cmpl.conn_id;
|
||||
LOG_INFO("SEARCH_CMPL: conn_id = %x, status %d\n", conn_id, p_data->search_cmpl.status);
|
||||
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, NULL);
|
||||
break;
|
||||
case ESP_GATTC_GET_CHAR_EVT:
|
||||
if (p_data->get_char.status != ESP_GATT_OK) {
|
||||
break;
|
||||
}
|
||||
LOG_INFO("GET CHAR: conn_id = %x, status %d\n", p_data->get_char.conn_id, p_data->get_char.status);
|
||||
LOG_INFO("GET CHAR: srvc_id = %04x, char_id = %04x\n", p_data->get_char.srvc_id.id.uuid.uuid.uuid16, p_data->get_char.char_id.uuid.uuid.uuid16);
|
||||
|
||||
if (p_data->get_char.char_id.uuid.uuid.uuid16 == 0x2a46) {
|
||||
LOG_INFO("register notify\n");
|
||||
esp_ble_gattc_register_for_notify(gattc_if, gl_profile_tab[PROFILE_B_APP_ID].remote_bda, &alert_service_id, &p_data->get_char.char_id);
|
||||
}
|
||||
|
||||
esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, &p_data->get_char.char_id);
|
||||
break;
|
||||
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
|
||||
uint16_t notify_en = 1;
|
||||
LOG_INFO("REG FOR NOTIFY: status %d\n", p_data->reg_for_notify.status);
|
||||
LOG_INFO("REG FOR_NOTIFY: srvc_id = %04x, char_id = %04x\n", p_data->reg_for_notify.srvc_id.id.uuid.uuid.uuid16, p_data->reg_for_notify.char_id.uuid.uuid.uuid16);
|
||||
|
||||
esp_ble_gattc_write_char_descr(
|
||||
gattc_if,
|
||||
conn_id,
|
||||
&alert_service_id,
|
||||
&p_data->reg_for_notify.char_id,
|
||||
¬ify_descr_id,
|
||||
sizeof(notify_en),
|
||||
(uint8_t *)¬ify_en,
|
||||
ESP_GATT_WRITE_TYPE_RSP,
|
||||
ESP_GATT_AUTH_REQ_NONE);
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_NOTIFY_EVT:
|
||||
LOG_INFO("NOTIFY: len %d, value %08x\n", p_data->notify.value_len, *(uint32_t *)p_data->notify.value);
|
||||
break;
|
||||
case ESP_GATTC_WRITE_DESCR_EVT:
|
||||
LOG_INFO("WRITE: status %d\n", p_data->write.status);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
|
||||
{
|
||||
uint8_t *adv_name = NULL;
|
||||
uint8_t adv_name_len = 0;
|
||||
@ -94,12 +316,13 @@ static void esp_gap_cb(uint32_t event, void *param)
|
||||
|
||||
if (adv_name != NULL) {
|
||||
if (strcmp((char *)adv_name, device_name) == 0) {
|
||||
LOG_INFO("the name eque to Heart Rate.\n");
|
||||
if (status == ESP_GATT_OK && connet == false) {
|
||||
connet = true;
|
||||
LOG_INFO("Connet to the remote device.\n");
|
||||
LOG_INFO("the name equal to Heart Rate\n");
|
||||
if (connect == false) {
|
||||
connect = true;
|
||||
LOG_INFO("Connect to the remote device.\n");
|
||||
esp_ble_gap_stop_scanning();
|
||||
esp_ble_gattc_open(client_if, scan_result->scan_rst.bda, true);
|
||||
esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, true);
|
||||
esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, scan_result->scan_rst.bda, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,55 +339,41 @@ static void esp_gap_cb(uint32_t event, void *param)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void esp_gattc_cb(uint32_t event, void *param)
|
||||
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
|
||||
{
|
||||
uint16_t conn_id = 0;
|
||||
esp_ble_gattc_cb_param_t *p_data = (esp_ble_gattc_cb_param_t *)param;
|
||||
LOG_INFO("EVT %d, gattc if %d\n", event, gattc_if);
|
||||
|
||||
LOG_INFO("esp_gattc_cb, event = %x\n", event);
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
status = p_data->reg.status;
|
||||
client_if = p_data->reg.gatt_if;
|
||||
LOG_INFO("status = %x, client_if = %x\n", status, client_if);
|
||||
break;
|
||||
case ESP_GATTC_OPEN_EVT:
|
||||
conn_id = p_data->open.conn_id;
|
||||
LOG_INFO("ESP_GATTC_OPEN_EVT conn_id %d, if %d, status %d\n", conn_id, p_data->open.gatt_if, p_data->open.status);
|
||||
esp_ble_gattc_search_service(conn_id, NULL);
|
||||
break;
|
||||
case ESP_GATTC_SEARCH_RES_EVT: {
|
||||
esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id;
|
||||
conn_id = p_data->open.conn_id;
|
||||
LOG_INFO("SEARCH RES: conn_id = %x\n", conn_id);
|
||||
if (srvc_id->id.uuid.len == ESP_UUID_LEN_16) {
|
||||
LOG_INFO("UUID16: %x\n", srvc_id->id.uuid.uuid.uuid16);
|
||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_32) {
|
||||
LOG_INFO("UUID32: %x\n", srvc_id->id.uuid.uuid.uuid32);
|
||||
} else if (srvc_id->id.uuid.len == ESP_UUID_LEN_128) {
|
||||
LOG_INFO("UUID128: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", srvc_id->id.uuid.uuid.uuid128[0],
|
||||
srvc_id->id.uuid.uuid.uuid128[1], srvc_id->id.uuid.uuid.uuid128[2], srvc_id->id.uuid.uuid.uuid128[3],
|
||||
srvc_id->id.uuid.uuid.uuid128[4], srvc_id->id.uuid.uuid.uuid128[5], srvc_id->id.uuid.uuid.uuid128[6],
|
||||
srvc_id->id.uuid.uuid.uuid128[7], srvc_id->id.uuid.uuid.uuid128[8], srvc_id->id.uuid.uuid.uuid128[9],
|
||||
srvc_id->id.uuid.uuid.uuid128[10], srvc_id->id.uuid.uuid.uuid128[11], srvc_id->id.uuid.uuid.uuid128[12],
|
||||
srvc_id->id.uuid.uuid.uuid128[13], srvc_id->id.uuid.uuid.uuid128[14], srvc_id->id.uuid.uuid.uuid128[15]);
|
||||
/* If event is register event, store the gattc_if for each profile */
|
||||
if (event == ESP_GATTC_REG_EVT) {
|
||||
if (param->reg.status == ESP_GATT_OK) {
|
||||
gl_profile_tab[param->reg.app_id].gattc_if = gattc_if;
|
||||
} else {
|
||||
LOG_ERROR("UNKNOWN LEN %d\n", srvc_id->id.uuid.len);
|
||||
LOG_INFO("Reg app failed, app_id %04x, status %d\n",
|
||||
param->reg.app_id,
|
||||
param->reg.status);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||
conn_id = p_data->search_cmpl.conn_id;
|
||||
LOG_INFO("SEARCH_CMPL: conn_id = %x, status %d\n", conn_id, p_data->search_cmpl.status);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* If the gattc_if equal to profile A, call profile A cb handler,
|
||||
* so here call each profile's callback */
|
||||
do {
|
||||
int idx;
|
||||
for (idx = 0; idx < PROFILE_NUM; idx++) {
|
||||
if (gattc_if == ESP_GATT_IF_NONE || /* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */
|
||||
gattc_if == gl_profile_tab[idx].gattc_if) {
|
||||
if (gl_profile_tab[idx].gattc_cb) {
|
||||
gl_profile_tab[idx].gattc_cb(event, gattc_if, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
|
||||
void ble_client_appRegister(void)
|
||||
{
|
||||
esp_err_t status;
|
||||
|
||||
LOG_INFO("register callback\n");
|
||||
|
||||
//register the scan callback function to the gap moudule
|
||||
@ -178,8 +387,8 @@ void ble_client_appRegister(void)
|
||||
LOG_ERROR("gattc register error, error code = %x\n", status);
|
||||
return;
|
||||
}
|
||||
esp_ble_gattc_app_register(simpleClient_id);
|
||||
esp_ble_gap_set_scan_params(&ble_scan_params);
|
||||
esp_ble_gattc_app_register(PROFILE_A_APP_ID);
|
||||
esp_ble_gattc_app_register(PROFILE_B_APP_ID);
|
||||
}
|
||||
|
||||
void gattc_client_test(void)
|
||||
|
Loading…
Reference in New Issue
Block a user