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 "esp_gatt_defs.h"
|
|
|
|
#include "esp_gatts_api.h"
|
2017-01-10 22:04:41 -05:00
|
|
|
#include "esp_bt_main.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "btc/btc_manage.h"
|
2016-11-15 07:56:15 -05:00
|
|
|
#include "btc_gatts.h"
|
2016-12-11 03:36:47 -05:00
|
|
|
#include "btc_gatt_util.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "common/bt_target.h"
|
2017-12-07 03:07:36 -05:00
|
|
|
#include "stack/l2cdefs.h"
|
|
|
|
#include "stack/l2c_api.h"
|
|
|
|
|
2017-04-20 07:18:05 -04:00
|
|
|
#if (GATTS_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
#define COPY_TO_GATTS_ARGS(_gatt_args, _arg, _arg_type) memcpy(_gatt_args, _arg, sizeof(_arg_type))
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-06-07 08:06:49 -04:00
|
|
|
static esp_err_t esp_ble_gatts_add_char_desc_param_check(esp_attr_value_t *char_val, esp_attr_control_t *control);
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-29 06:45:10 -05:00
|
|
|
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
|
|
|
|
if (app_id > ESP_APP_ID_MAX) {
|
2016-11-24 13:10:15 -05:00
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_APP_REGISTER;
|
|
|
|
arg.app_reg.app_id = app_id;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2016-12-23 11:28:47 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_APP_UNREGISTER;
|
2016-12-11 03:36:47 -05:00
|
|
|
arg.app_unreg.gatts_if = gatts_if;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_gatt_srvc_id_t *service_id, uint16_t num_handle)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_CREATE_SERVICE;
|
2016-12-11 03:36:47 -05:00
|
|
|
arg.create_srvc.gatts_if = gatts_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
arg.create_srvc.num_handle = num_handle;
|
|
|
|
memcpy(&arg.create_srvc.service_id, service_id, sizeof(esp_gatt_srvc_id_t));
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_create_attr_tab(const esp_gatts_attr_db_t *gatts_attr_db,
|
|
|
|
esp_gatt_if_t gatts_if,
|
|
|
|
uint8_t max_nb_attr,
|
|
|
|
uint8_t srvc_inst_id)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_CREATE_ATTR_TAB;
|
|
|
|
arg.create_attr_tab.gatts_if = gatts_if;
|
|
|
|
arg.create_attr_tab.max_nb_attr = max_nb_attr;
|
|
|
|
arg.create_attr_tab.srvc_inst_id = srvc_inst_id;
|
|
|
|
arg.create_attr_tab.gatts_attr_db = (esp_gatts_attr_db_t *)gatts_attr_db;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-28 01:58:30 -05:00
|
|
|
esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t included_service_handle)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_ADD_INCLUDE_SERVICE;
|
|
|
|
arg.add_incl_srvc.service_handle = service_handle;
|
|
|
|
arg.add_incl_srvc.included_service_handle = included_service_handle;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_uuid,
|
2016-12-23 11:28:47 -05:00
|
|
|
esp_gatt_perm_t perm, esp_gatt_char_prop_t property, esp_attr_value_t *char_val,
|
|
|
|
esp_attr_control_t *control)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2017-06-07 08:06:49 -04:00
|
|
|
esp_err_t status;
|
2016-11-24 13:10:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2016-12-23 11:28:47 -05:00
|
|
|
|
2017-03-06 04:20:45 -05:00
|
|
|
/* parameter validation check */
|
2017-06-07 08:06:49 -04:00
|
|
|
status = esp_ble_gatts_add_char_desc_param_check(char_val, control);
|
|
|
|
if (status != ESP_OK){
|
|
|
|
return status;
|
2017-03-06 04:20:45 -05:00
|
|
|
}
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
memset(&arg, 0, sizeof(btc_ble_gatts_args_t));
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_ADD_CHAR;
|
|
|
|
arg.add_char.service_handle = service_handle;
|
|
|
|
arg.add_char.perm = perm;
|
|
|
|
arg.add_char.property = property;
|
2016-12-23 11:28:47 -05:00
|
|
|
if (char_val != NULL) {
|
|
|
|
arg.add_char.char_val.attr_max_len = char_val->attr_max_len;
|
|
|
|
arg.add_char.char_val.attr_len = char_val->attr_len;
|
|
|
|
arg.add_char.char_val.attr_value = char_val->attr_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (control != NULL) {
|
|
|
|
arg.add_char.attr_control.auto_rsp = control->auto_rsp;
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
memcpy(&arg.add_char.char_uuid, char_uuid, sizeof(esp_bt_uuid_t));
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_bt_uuid_t *descr_uuid,
|
2016-12-23 11:28:47 -05:00
|
|
|
esp_gatt_perm_t perm, esp_attr_value_t *char_descr_val,
|
|
|
|
esp_attr_control_t *control)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2017-06-07 08:06:49 -04:00
|
|
|
esp_err_t status;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-03-06 04:20:45 -05:00
|
|
|
|
|
|
|
/* parameter validation check */
|
2017-06-07 08:06:49 -04:00
|
|
|
status = esp_ble_gatts_add_char_desc_param_check(char_descr_val, control);
|
|
|
|
if (status != ESP_OK){
|
|
|
|
return status;
|
2017-03-06 04:20:45 -05:00
|
|
|
}
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
memset(&arg, 0, sizeof(btc_ble_gatts_args_t));
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_ADD_CHAR_DESCR;
|
|
|
|
arg.add_descr.service_handle = service_handle;
|
|
|
|
arg.add_descr.perm = perm;
|
2016-12-23 11:28:47 -05:00
|
|
|
|
|
|
|
if (char_descr_val != NULL) {
|
|
|
|
arg.add_descr.descr_val.attr_max_len = char_descr_val->attr_max_len;
|
|
|
|
arg.add_descr.descr_val.attr_len = char_descr_val->attr_len;
|
|
|
|
arg.add_descr.descr_val.attr_value = char_descr_val->attr_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (control != NULL) {
|
|
|
|
arg.add_descr.attr_control.auto_rsp = control->auto_rsp;
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
memcpy(&arg.add_descr.descr_uuid, descr_uuid, sizeof(esp_bt_uuid_t));
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_DELETE_SERVICE;
|
|
|
|
arg.delete_srvc.service_handle = service_handle;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gatts_start_service(uint16_t service_handle)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_START_SERVICE;
|
|
|
|
arg.start_srvc.service_handle = service_handle;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2016-12-23 11:28:47 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_STOP_SERVICE;
|
|
|
|
arg.stop_srvc.service_handle = service_handle;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id, uint16_t attr_handle,
|
2016-11-24 13:10:15 -05:00
|
|
|
uint16_t value_len, uint8_t *value, bool need_confirm)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2017-12-07 03:07:36 -05:00
|
|
|
if (L2CA_CheckIsCongest(L2CAP_ATT_CID, conn_id)) {
|
2018-06-21 08:13:05 -04:00
|
|
|
LOG_DEBUG("%s, the l2cap chanel is congest.", __func__);
|
2017-12-07 03:07:36 -05:00
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_SEND_INDICATE;
|
2016-12-11 03:36:47 -05:00
|
|
|
arg.send_ind.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
2016-11-24 13:10:15 -05:00
|
|
|
arg.send_ind.attr_handle = attr_handle;
|
|
|
|
arg.send_ind.need_confirm = need_confirm;
|
|
|
|
arg.send_ind.value_len = value_len;
|
|
|
|
arg.send_ind.value = value;
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t),
|
|
|
|
btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_send_response(esp_gatt_if_t gatts_if, uint16_t conn_id, uint32_t trans_id,
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_gatt_status_t status, esp_gatt_rsp_t *rsp)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_SEND_RESPONSE;
|
2016-12-11 03:36:47 -05:00
|
|
|
arg.send_rsp.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
2016-11-24 13:10:15 -05:00
|
|
|
arg.send_rsp.trans_id = trans_id;
|
|
|
|
arg.send_rsp.status = status;
|
|
|
|
arg.send_rsp.rsp = rsp;
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
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_set_attr_value(uint16_t attr_handle, uint16_t length, const uint8_t *value)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_SET_ATTR_VALUE;
|
2017-04-28 07:23:52 -04:00
|
|
|
arg.set_attr_val.handle = attr_handle;
|
2016-12-23 11:28:47 -05:00
|
|
|
arg.set_attr_val.length = length;
|
|
|
|
arg.set_attr_val.value = (uint8_t *)value;
|
|
|
|
|
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t),
|
|
|
|
btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
|
|
}
|
|
|
|
|
2017-08-14 05:39:11 -04:00
|
|
|
esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value)
|
2016-12-23 11:28:47 -05:00
|
|
|
{
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
if (attr_handle == ESP_GATT_ILLEGAL_HANDLE) {
|
2017-08-14 05:39:11 -04:00
|
|
|
return ESP_GATT_INVALID_HANDLE;
|
2016-12-23 11:28:47 -05:00
|
|
|
}
|
2017-08-14 05:39:11 -04:00
|
|
|
|
|
|
|
return btc_gatts_get_attr_value(attr_handle, length, (uint8_t **)value);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2017-01-10 22:04:41 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_OPEN;
|
2016-12-11 03:36:47 -05:00
|
|
|
arg.open.gatts_if = gatts_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
arg.open.is_direct = is_direct;
|
|
|
|
memcpy(&arg.open.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
|
2016-11-15 07:56:15 -05:00
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2017-08-08 05:28:19 -04:00
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
2016-12-23 11:28:47 -05:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_CLOSE;
|
2016-12-11 03:36:47 -05:00
|
|
|
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
2016-11-15 07:56:15 -05:00
|
|
|
|
2016-12-23 11:28:47 -05:00
|
|
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL)
|
|
|
|
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
2016-11-15 07:56:15 -05:00
|
|
|
}
|
2017-04-20 07:18:05 -04:00
|
|
|
|
2018-09-18 04:20:13 -04:00
|
|
|
esp_err_t esp_ble_gatts_send_service_change_indication(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda)
|
|
|
|
{
|
|
|
|
btc_msg_t msg;
|
|
|
|
btc_ble_gatts_args_t arg;
|
|
|
|
|
|
|
|
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
|
|
|
|
|
|
|
msg.sig = BTC_SIG_API_CALL;
|
|
|
|
msg.pid = BTC_PID_GATTS;
|
|
|
|
msg.act = BTC_GATTS_ACT_SEND_SERVICE_CHANGE;
|
|
|
|
arg.send_service_change.gatts_if = gatts_if;
|
|
|
|
if(remote_bda) {
|
|
|
|
memcpy(&arg.send_service_change.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
|
|
|
|
} else {
|
|
|
|
memset(arg.send_service_change.remote_bda, 0, 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);
|
|
|
|
}
|
2017-06-07 08:06:49 -04:00
|
|
|
|
|
|
|
static esp_err_t esp_ble_gatts_add_char_desc_param_check(esp_attr_value_t *char_val, esp_attr_control_t *control)
|
|
|
|
{
|
|
|
|
if ((control != NULL) && ((control->auto_rsp != ESP_GATT_AUTO_RSP) && (control->auto_rsp != ESP_GATT_RSP_BY_APP))){
|
|
|
|
LOG_ERROR("Error in %s, line=%d, control->auto_rsp should be set to ESP_GATT_AUTO_RSP or ESP_GATT_RSP_BY_APP\n",\
|
|
|
|
__func__, __LINE__);
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((control != NULL) && (control->auto_rsp == ESP_GATT_AUTO_RSP)){
|
|
|
|
if (char_val == NULL){
|
|
|
|
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, char_val should not be NULL here\n",\
|
|
|
|
__func__, __LINE__);
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
} else if (char_val->attr_max_len == 0){
|
|
|
|
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
|
|
|
|
__func__, __LINE__);
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif ///GATTS_INCLUDED
|