2016-11-15 07:56:15 -05:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "bta_gatt_api.h"
|
|
|
|
|
|
|
|
#include "btc_task.h"
|
|
|
|
#include "btc_manage.h"
|
|
|
|
#include "btc_gatts.h"
|
|
|
|
#include "btc_gatt_util.h"
|
|
|
|
|
|
|
|
#include "esp_gatts_api.h"
|
|
|
|
|
2017-01-10 22:31:35 -05:00
|
|
|
#define BTC_GATTS_CB_TO_APP(event, gatts_if, param) do { \
|
|
|
|
esp_gatts_cb_t btc_gatts_cb = (esp_gatts_cb_t)btc_profile_cb_get(BTC_PID_GATTS); \
|
|
|
|
if (btc_gatts_cb) { \
|
|
|
|
btc_gatts_cb(event, gatts_if, param); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2016-11-15 07:56:15 -05:00
|
|
|
|
|
|
|
#define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT
|
|
|
|
#define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT
|
|
|
|
|
2016-11-23 00:45:21 -05:00
|
|
|
void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_ble_gatts_args_t *dst = (btc_ble_gatts_args_t *) p_dest;
|
|
|
|
btc_ble_gatts_args_t *src = (btc_ble_gatts_args_t *)p_src;
|
|
|
|
|
|
|
|
switch (msg->act) {
|
|
|
|
case BTC_GATTS_ACT_SEND_INDICATE: {
|
|
|
|
dst->send_ind.value = (uint8_t *)GKI_getbuf(src->send_ind.value_len);
|
|
|
|
if (dst->send_ind.value) {
|
|
|
|
memcpy(dst->send_ind.value, src->send_ind.value, src->send_ind.value_len);
|
|
|
|
} else {
|
|
|
|
LOG_ERROR("%s %d no mem\n", __func__, msg->act);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_SEND_RESPONSE: {
|
|
|
|
if (src->send_rsp.rsp) {
|
|
|
|
dst->send_rsp.rsp = (esp_gatt_rsp_t *)GKI_getbuf(sizeof(esp_gatt_rsp_t));
|
|
|
|
if (dst->send_rsp.rsp) {
|
|
|
|
memcpy(dst->send_rsp.rsp, src->send_rsp.rsp, sizeof(esp_gatt_rsp_t));
|
|
|
|
} else {
|
|
|
|
LOG_ERROR("%s %d no mem\n", __func__, msg->act);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
LOG_DEBUG("%s Unhandled deep copy %d\n", __func__, msg->act);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-23 00:45:21 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void btc_gatts_arg_deep_free(btc_msg_t *msg)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_ble_gatts_args_t *arg = (btc_ble_gatts_args_t *)msg->arg;
|
|
|
|
|
|
|
|
switch (msg->act) {
|
|
|
|
case BTC_GATTS_ACT_SEND_INDICATE: {
|
|
|
|
if (arg->send_ind.value) {
|
|
|
|
GKI_freebuf(arg->send_ind.value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_SEND_RESPONSE: {
|
|
|
|
if (arg->send_rsp.rsp) {
|
|
|
|
GKI_freebuf(arg->send_rsp.rsp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
LOG_DEBUG("%s Unhandled deep free %d\n", __func__, msg->act);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-23 00:45:21 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-15 07:56:15 -05:00
|
|
|
static void btc_gatts_cb_param_copy_req(btc_msg_t *msg, void *p_dest, void *p_src)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
uint16_t event = msg->act;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
tBTA_GATTS *p_dest_data = (tBTA_GATTS *) p_dest;
|
|
|
|
tBTA_GATTS *p_src_data = (tBTA_GATTS *) p_src;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!p_src_data || !p_dest_data) {
|
2016-11-15 07:56:15 -05:00
|
|
|
return;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-11-15 07:56:15 -05:00
|
|
|
|
|
|
|
// Copy basic structure first
|
|
|
|
memcpy(p_dest_data, p_src_data, sizeof(tBTA_GATTS));
|
|
|
|
|
|
|
|
// Allocate buffer for request data if necessary
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (event) {
|
|
|
|
case BTA_GATTS_READ_EVT:
|
|
|
|
case BTA_GATTS_WRITE_EVT:
|
|
|
|
case BTA_GATTS_EXEC_WRITE_EVT:
|
|
|
|
case BTA_GATTS_MTU_EVT:
|
|
|
|
p_dest_data->req_data.p_data = GKI_getbuf(sizeof(tBTA_GATTS_REQ_DATA));
|
|
|
|
if (p_dest_data->req_data.p_data != NULL) {
|
|
|
|
memcpy(p_dest_data->req_data.p_data, p_src_data->req_data.p_data,
|
|
|
|
sizeof(tBTA_GATTS_REQ_DATA));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void btc_gatts_cb_param_copy_free(btc_msg_t *msg, tBTA_GATTS *p_data)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
uint16_t event = msg->act;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case BTA_GATTS_READ_EVT:
|
|
|
|
case BTA_GATTS_WRITE_EVT:
|
|
|
|
case BTA_GATTS_EXEC_WRITE_EVT:
|
|
|
|
case BTA_GATTS_MTU_EVT:
|
|
|
|
if (p_data && p_data->req_data.p_data) {
|
|
|
|
GKI_freebuf(p_data->req_data.p_data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
bt_status_t status;
|
|
|
|
btc_msg_t msg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CB;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = event;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
status = btc_transfer_context(&msg, p_data,
|
|
|
|
sizeof(tBTA_GATTS), btc_gatts_cb_param_copy_req);
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (status != BT_STATUS_SUCCESS) {
|
|
|
|
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
|
|
|
}
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void btc_gatts_call_handler(btc_msg_t *msg)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_ble_gatts_args_t *arg = (btc_ble_gatts_args_t *)msg->arg;
|
|
|
|
|
|
|
|
switch (msg->act) {
|
|
|
|
case BTC_GATTS_ACT_APP_REGISTER: {
|
|
|
|
tBT_UUID uuid;
|
|
|
|
|
|
|
|
uuid.len = LEN_UUID_16;
|
|
|
|
uuid.uu.uuid16 = arg->app_reg.app_id;
|
|
|
|
|
|
|
|
BTA_GATTS_AppRegister(&uuid, btc_gatts_inter_cb);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_APP_UNREGISTER:
|
2016-12-11 03:36:47 -05:00
|
|
|
BTA_GATTS_AppDeregister(arg->app_unreg.gatts_if);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTC_GATTS_ACT_CREATE_SERVICE: {
|
2016-11-15 07:56:15 -05:00
|
|
|
tBTA_GATT_SRVC_ID srvc_id;
|
2016-11-23 00:45:21 -05:00
|
|
|
btc_to_bta_srvc_id(&srvc_id, &arg->create_srvc.service_id);
|
2016-12-11 03:36:47 -05:00
|
|
|
BTA_GATTS_CreateService(arg->create_srvc.gatts_if, &srvc_id.id.uuid,
|
2016-11-23 00:45:21 -05:00
|
|
|
srvc_id.id.inst_id, arg->create_srvc.num_handle,
|
2016-11-15 07:56:15 -05:00
|
|
|
srvc_id.is_primary);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_DELETE_SERVICE:
|
|
|
|
BTA_GATTS_DeleteService(arg->delete_srvc.service_handle);
|
|
|
|
break;
|
|
|
|
case BTC_GATTS_ACT_START_SERVICE:
|
|
|
|
BTA_GATTS_StartService(arg->start_srvc.service_handle, BTA_GATT_TRANSPORT_LE);
|
|
|
|
break;
|
|
|
|
case BTC_GATTS_ACT_STOP_SERVICE:
|
|
|
|
BTA_GATTS_StopService(arg->stop_srvc.service_handle);
|
|
|
|
break;
|
|
|
|
case BTC_GATTS_ACT_ADD_INCLUDE_SERVICE:
|
|
|
|
BTA_GATTS_AddIncludeService(arg->add_incl_srvc.service_handle, arg->add_incl_srvc.included_service_handle);
|
|
|
|
break;
|
|
|
|
case BTC_GATTS_ACT_ADD_CHAR: {
|
|
|
|
tBT_UUID uuid;
|
|
|
|
btc_to_bta_uuid(&uuid, &arg->add_char.char_uuid);
|
|
|
|
|
|
|
|
BTA_GATTS_AddCharacteristic(arg->add_char.service_handle, &uuid,
|
|
|
|
arg->add_char.perm, arg->add_char.property);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_ADD_CHAR_DESCR: {
|
|
|
|
tBT_UUID uuid;
|
|
|
|
btc_to_bta_uuid(&uuid, &arg->add_descr.descr_uuid);
|
|
|
|
BTA_GATTS_AddCharDescriptor(arg->add_descr.service_handle, arg->add_descr.perm, &uuid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_SEND_INDICATE:
|
|
|
|
BTA_GATTS_HandleValueIndication(arg->send_ind.conn_id, arg->send_ind.attr_handle,
|
2016-11-23 00:45:21 -05:00
|
|
|
arg->send_ind.value_len, arg->send_ind.value, arg->send_ind.need_confirm);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTC_GATTS_ACT_SEND_RESPONSE: {
|
|
|
|
esp_ble_gatts_cb_param_t param;
|
|
|
|
esp_gatt_rsp_t *p_rsp = arg->send_rsp.rsp;
|
|
|
|
|
|
|
|
if (p_rsp) {
|
|
|
|
tBTA_GATTS_RSP rsp_struct;
|
|
|
|
btc_to_bta_response(&rsp_struct, p_rsp);
|
|
|
|
BTA_GATTS_SendRsp(arg->send_rsp.conn_id, arg->send_rsp.trans_id,
|
|
|
|
arg->send_rsp.status, &rsp_struct);
|
|
|
|
param.rsp.handle = rsp_struct.attr_value.handle;
|
|
|
|
} else {
|
|
|
|
BTA_GATTS_SendRsp(arg->send_rsp.conn_id, arg->send_rsp.trans_id,
|
|
|
|
arg->send_rsp.status, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
param.rsp.status = 0;
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_RESPONSE_EVT, BTC_GATT_GET_GATT_IF(arg->send_rsp.conn_id), ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_OPEN: {
|
|
|
|
// Ensure device is in inquiry database
|
|
|
|
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
|
|
|
|
|
|
|
|
//TODO : implement address type and device type
|
2016-11-15 07:56:15 -05:00
|
|
|
#if 0
|
2016-11-24 13:10:15 -05:00
|
|
|
if (_get_address_type(arg->remote_bda, &addr_type) &&
|
|
|
|
btif_get_device_type(arg->remote_bda, &device_type) &&
|
|
|
|
device_type != BT_DEVICE_TYPE_BREDR) {
|
|
|
|
BTA_DmAddBleDevice(p_cb->bd_addr.address, addr_type, device_type);
|
|
|
|
}
|
2016-11-15 07:56:15 -05:00
|
|
|
#else
|
2016-11-24 13:10:15 -05:00
|
|
|
//BTA_DmAddBleDevice(p_cb->bd_addr.address, addr_type, device_type);
|
2016-11-15 07:56:15 -05:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
// Mark background connections
|
|
|
|
if (!arg->open.is_direct) {
|
|
|
|
BTA_DmBleSetBgConnType(BTM_BLE_CONN_AUTO, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
transport = BTA_GATT_TRANSPORT_LE;
|
|
|
|
|
|
|
|
// Connect!
|
2016-12-11 03:36:47 -05:00
|
|
|
BTA_GATTS_Open(arg->open.gatts_if, arg->open.remote_bda,
|
2016-11-24 13:10:15 -05:00
|
|
|
arg->open.is_direct, transport);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTC_GATTS_ACT_CLOSE:
|
|
|
|
// TODO : implement cancel open
|
|
|
|
// Cancel pending foreground/background connections
|
2016-11-15 07:56:15 -05:00
|
|
|
//BTA_GATTS_CancelOpen(p_cb->server_if, p_cb->bd_addr.address, TRUE);
|
|
|
|
//BTA_GATTS_CancelOpen(p_cb->server_if, p_cb->bd_addr.address, FALSE);
|
|
|
|
|
|
|
|
// Close active connection
|
2016-11-24 13:10:15 -05:00
|
|
|
if (arg->close.conn_id != 0) {
|
|
|
|
BTA_GATTS_Close(arg->close.conn_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
btc_gatts_arg_deep_free(msg);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void btc_gatts_cb_handler(btc_msg_t *msg)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_ble_gatts_cb_param_t param;
|
|
|
|
tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg;
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_gatt_if_t gatts_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
switch (msg->act) {
|
|
|
|
case BTA_GATTS_REG_EVT: {
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->reg_oper.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.reg.status = p_data->reg_oper.status;
|
|
|
|
param.reg.app_id = p_data->reg_oper.uuid.uu.uuid16;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_REG_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
2016-12-11 03:36:47 -05:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTA_GATTS_READ_EVT: {
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
param.read.trans_id = p_data->req_data.trans_id;
|
|
|
|
memcpy(param.read.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
|
2017-01-10 22:31:35 -05:00
|
|
|
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;
|
2016-11-24 13:10:15 -05:00
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_READ_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTA_GATTS_WRITE_EVT: {
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
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;
|
|
|
|
param.write.offset = p_data->req_data.p_data->write_req.offset;
|
|
|
|
param.write.need_rsp = p_data->req_data.p_data->write_req.need_rsp;
|
|
|
|
param.write.is_prep = p_data->req_data.p_data->write_req.is_prep;
|
|
|
|
param.write.len = p_data->req_data.p_data->write_req.len;
|
|
|
|
param.write.value = p_data->req_data.p_data->write_req.value;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_WRITE_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTA_GATTS_EXEC_WRITE_EVT: {
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
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;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_EXEC_WRITE_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BTA_GATTS_MTU_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
param.mtu.mtu = p_data->req_data.p_data->mtu;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_MTU_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_CONF_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
param.conf.status = p_data->req_data.status;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONF_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_CREATE_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->create.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.create.status = p_data->create.status;
|
|
|
|
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);
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_ADD_INCL_SRVC_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->add_result.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.add_incl_srvc.status = p_data->add_result.status;
|
|
|
|
param.add_incl_srvc.attr_handle = p_data->add_result.attr_id;
|
|
|
|
param.add_incl_srvc.service_handle = p_data->add_result.service_id;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_INCL_SRVC_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_ADD_CHAR_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->add_result.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.add_char.status = p_data->add_result.status;
|
|
|
|
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);
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->add_result.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.add_char_descr.status = p_data->add_result.status;
|
|
|
|
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);
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_DESCR_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_DELELTE_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->srvc_oper.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.del.status = p_data->srvc_oper.status;
|
|
|
|
param.del.service_handle = p_data->srvc_oper.service_id;
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELETE_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_START_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->srvc_oper.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.start.status = p_data->srvc_oper.status;
|
|
|
|
param.start.service_handle = p_data->srvc_oper.service_id;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_START_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_STOP_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->srvc_oper.server_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
param.stop.status = p_data->srvc_oper.status;
|
|
|
|
param.stop.service_handle = p_data->srvc_oper.service_id;
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_STOP_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_CONNECT_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
gatts_if = p_data->conn.server_if;
|
|
|
|
param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
|
2016-11-24 13:10:15 -05:00
|
|
|
param.connect.is_connected = true;
|
|
|
|
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONNECT_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_DISCONNECT_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_DISCONNECT_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
case BTA_GATTS_OPEN_EVT:
|
|
|
|
// do nothing
|
|
|
|
case BTA_GATTS_CANCEL_OPEN_EVT:
|
|
|
|
// do nothing
|
|
|
|
case BTA_GATTS_CLOSE_EVT:
|
|
|
|
// do nothing
|
|
|
|
case BTA_GATTS_LISTEN_EVT:
|
|
|
|
// do nothing
|
|
|
|
break;
|
|
|
|
case BTA_GATTS_CONGEST_EVT:
|
2016-12-11 03:36:47 -05:00
|
|
|
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);
|
2016-11-24 13:10:15 -05:00
|
|
|
param.congest.congested = p_data->congest.congested;
|
2016-12-11 03:36:47 -05:00
|
|
|
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONGEST_EVT, gatts_if, ¶m);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
btc_gatts_cb_param_copy_free(msg, p_data);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|