2016-11-24 12:58:26 -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.
|
|
|
|
|
2016-11-15 07:56:15 -05:00
|
|
|
#ifndef __BTC_GATTC_H__
|
|
|
|
#define __BTC_GATTC_H__
|
|
|
|
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "btc/btc_task.h"
|
2016-11-15 13:10:37 -05:00
|
|
|
#include "esp_bt_defs.h"
|
|
|
|
#include "esp_gatt_defs.h"
|
|
|
|
#include "esp_gattc_api.h"
|
2016-11-15 07:56:15 -05:00
|
|
|
|
|
|
|
typedef enum {
|
2016-11-23 08:27:05 -05:00
|
|
|
BTC_GATTC_ACT_APP_REGISTER = 0,
|
2016-11-15 07:56:15 -05:00
|
|
|
BTC_GATTC_ACT_APP_UNREGISTER,
|
|
|
|
BTC_GATTC_ACT_OPEN,
|
|
|
|
BTC_GATTC_ACT_CLOSE,
|
|
|
|
BTC_GATTC_ACT_CFG_MTU,
|
|
|
|
BTC_GATTC_ACT_SEARCH_SERVICE,
|
|
|
|
BTC_GATTC_ACT_READ_CHAR,
|
2017-08-24 02:24:04 -04:00
|
|
|
BTC_GATTC_ACT_READ_MULTIPLE_CHAR,
|
2016-11-15 07:56:15 -05:00
|
|
|
BTC_GATTC_ACT_READ_CHAR_DESCR,
|
2020-12-03 08:04:21 -05:00
|
|
|
BTC_GATTC_ACT_READ_BY_TYPE,
|
2016-11-15 07:56:15 -05:00
|
|
|
BTC_GATTC_ACT_WRITE_CHAR,
|
|
|
|
BTC_GATTC_ACT_WRITE_CHAR_DESCR,
|
|
|
|
BTC_GATTC_ACT_PREPARE_WRITE,
|
2017-04-28 02:51:23 -04:00
|
|
|
BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR,
|
2016-11-15 07:56:15 -05:00
|
|
|
BTC_GATTC_ACT_EXECUTE_WRITE,
|
|
|
|
BTC_GATTC_ACT_REG_FOR_NOTIFY,
|
2017-05-16 09:10:37 -04:00
|
|
|
BTC_GATTC_ACT_UNREG_FOR_NOTIFY,
|
|
|
|
BTC_GATTC_ACT_CACHE_REFRESH,
|
2018-04-20 02:16:33 -04:00
|
|
|
BTC_GATTC_ACT_CACHE_ASSOC,
|
2018-03-11 23:34:20 -04:00
|
|
|
BTC_GATTC_ATC_CACHE_GET_ADDR_LIST,
|
2016-11-15 07:56:15 -05:00
|
|
|
} btc_gattc_act_t;
|
|
|
|
|
2016-11-15 13:10:37 -05:00
|
|
|
/* btc_ble_gattc_args_t */
|
2016-11-23 21:50:16 -05:00
|
|
|
typedef union {
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_APP_REGISTER,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct app_reg_arg {
|
|
|
|
uint16_t app_id;
|
|
|
|
} app_reg;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_APP_UNREGISTER,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct app_unreg_arg {
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_gatt_if_t gattc_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
} app_unreg;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_OPEN,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct open_arg {
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_gatt_if_t gattc_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_bd_addr_t remote_bda;
|
2018-03-22 23:08:03 -04:00
|
|
|
esp_ble_addr_type_t remote_addr_type;
|
2016-11-24 13:10:15 -05:00
|
|
|
bool is_direct;
|
|
|
|
} open;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_CLOSE,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct close_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
} close;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_CFG_MTU,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct cfg_mtu_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
} cfg_mtu;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_SEARCH_SERVICE,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct search_srvc_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
bool filter_uuid_enable;
|
|
|
|
esp_bt_uuid_t filter_uuid;
|
|
|
|
} search_srvc;
|
2017-08-24 02:24:04 -04:00
|
|
|
//BTC_GATTC_ACT_GET_CHAR,
|
|
|
|
struct get_char_arg {
|
2016-11-24 13:10:15 -05:00
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
|
|
|
} get_char;
|
|
|
|
//BTC_GATTC_ACT_GET_DESCR,
|
|
|
|
struct get_descr_arg {
|
2016-11-24 13:10:15 -05:00
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
|
|
|
} get_descr;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct get_first_incl_srvc_arg {
|
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
} get_first_incl_srvc;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct get_next_incl_srvc_arg {
|
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
} get_next_incl_srvc;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_READ_CHAR,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct read_char_arg {
|
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} read_char;
|
2017-08-24 02:24:04 -04:00
|
|
|
//BTC_GATTC_ACT_READ_MULTIPLE_CHAR
|
|
|
|
struct read_multiple_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
uint8_t num_attr;
|
|
|
|
uint16_t handles[ESP_GATT_MAX_READ_MULTI_HANDLES];
|
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} read_multiple;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_READ_CHAR_DESCR,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct read_descr_arg {
|
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} read_descr;
|
2020-12-03 08:04:21 -05:00
|
|
|
// BTC_GATTC_ACT_READ_BY_TYPE
|
|
|
|
struct read_by_type_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
uint16_t s_handle;
|
|
|
|
uint16_t e_handle;
|
|
|
|
esp_bt_uuid_t uuid;
|
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} read_by_type;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_WRITE_CHAR,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct write_char_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
uint16_t value_len;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
uint8_t *value;
|
2017-08-24 02:24:04 -04:00
|
|
|
esp_gatt_write_type_t write_type;
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} write_char;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_WRITE_CHAR_DESCR,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct write_descr_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
uint16_t value_len;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
uint8_t *value;
|
2017-08-24 02:24:04 -04:00
|
|
|
esp_gatt_write_type_t write_type;
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} write_descr;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_PREPARE_WRITE,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct prep_write_arg {
|
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
uint16_t offset;
|
|
|
|
uint16_t value_len;
|
|
|
|
uint8_t *value;
|
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} prep_write;
|
2017-04-28 02:51:23 -04:00
|
|
|
//BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR,
|
|
|
|
struct prep_write_descr_arg {
|
|
|
|
uint16_t conn_id;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2017-04-28 02:51:23 -04:00
|
|
|
uint16_t offset;
|
|
|
|
uint16_t value_len;
|
|
|
|
uint8_t *value;
|
|
|
|
esp_gatt_auth_req_t auth_req;
|
|
|
|
} prep_write_descr;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_EXECUTE_WRITE,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct exec_write_arg {
|
|
|
|
uint16_t conn_id;
|
|
|
|
bool is_execute;
|
|
|
|
} exec_write;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_REG_FOR_NOTIFY,
|
2016-11-24 13:10:15 -05:00
|
|
|
struct reg_for_notify_arg {
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_gatt_if_t gattc_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_bd_addr_t remote_bda;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
} reg_for_notify;
|
2016-11-23 08:27:05 -05:00
|
|
|
//BTC_GATTC_ACT_UNREG_FOR_NOTIFY
|
2016-11-24 13:10:15 -05:00
|
|
|
struct unreg_for_notify_arg {
|
2016-12-11 03:36:47 -05:00
|
|
|
esp_gatt_if_t gattc_if;
|
2016-11-24 13:10:15 -05:00
|
|
|
esp_bd_addr_t remote_bda;
|
2017-08-24 02:24:04 -04:00
|
|
|
uint16_t handle;
|
2016-11-24 13:10:15 -05:00
|
|
|
} unreg_for_notify;
|
2017-05-16 09:10:37 -04:00
|
|
|
//BTC_GATTC_ACT_CACHE_REFRESH,
|
|
|
|
struct cache_refresh_arg {
|
|
|
|
esp_bd_addr_t remote_bda;
|
|
|
|
} cache_refresh;
|
2018-04-20 02:16:33 -04:00
|
|
|
//BTC_GATTC_ACT_CACHE_ASSOC
|
|
|
|
struct cache_assoc_arg {
|
2018-03-11 23:34:20 -04:00
|
|
|
esp_gatt_if_t gattc_if;
|
|
|
|
esp_bd_addr_t src_addr;
|
2018-04-20 02:16:33 -04:00
|
|
|
esp_bd_addr_t assoc_addr;
|
|
|
|
bool is_assoc;
|
|
|
|
} cache_assoc;
|
2018-03-11 23:34:20 -04:00
|
|
|
//BTC_GATTC_ATC_CACHE_GET_ADDR_LIST
|
|
|
|
struct cache_get_addr_list_arg {
|
|
|
|
esp_gatt_if_t gattc_if;
|
|
|
|
}get_addr_list;
|
2016-11-15 13:10:37 -05:00
|
|
|
} btc_ble_gattc_args_t;
|
|
|
|
|
2016-11-15 07:56:15 -05:00
|
|
|
void btc_gattc_call_handler(btc_msg_t *msg);
|
|
|
|
void btc_gattc_cb_handler(btc_msg_t *msg);
|
2016-11-23 08:27:05 -05:00
|
|
|
void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
2017-08-24 02:24:04 -04:00
|
|
|
esp_gatt_status_t btc_ble_gattc_get_service(uint16_t conn_id, esp_bt_uuid_t *svc_uuid,
|
|
|
|
esp_gattc_service_elem_t *result,
|
|
|
|
uint16_t *count, uint16_t offset);
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_all_char(uint16_t conn_id,
|
|
|
|
uint16_t start_handle,
|
|
|
|
uint16_t end_handle,
|
|
|
|
esp_gattc_char_elem_t *result,
|
|
|
|
uint16_t *count, uint16_t offset);
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_all_descr(uint16_t conn_id,
|
|
|
|
uint16_t char_handle,
|
|
|
|
esp_gattc_descr_elem_t *result,
|
|
|
|
uint16_t *count, uint16_t offset);
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_char_by_uuid(uint16_t conn_id,
|
|
|
|
uint16_t start_handle,
|
|
|
|
uint16_t end_handle,
|
|
|
|
esp_bt_uuid_t char_uuid,
|
|
|
|
esp_gattc_char_elem_t *result,
|
|
|
|
uint16_t *count);
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_descr_by_uuid(uint16_t conn_id,
|
|
|
|
uint16_t start_handle,
|
|
|
|
uint16_t end_handle,
|
|
|
|
esp_bt_uuid_t char_uuid,
|
|
|
|
esp_bt_uuid_t descr_uuid,
|
|
|
|
esp_gattc_descr_elem_t *result,
|
|
|
|
uint16_t *count);
|
|
|
|
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_descr_by_char_handle(uint16_t conn_id,
|
|
|
|
uint16_t char_handle,
|
|
|
|
esp_bt_uuid_t descr_uuid,
|
|
|
|
esp_gattc_descr_elem_t *result,
|
|
|
|
uint16_t *count);
|
|
|
|
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_include_service(uint16_t conn_id,
|
|
|
|
uint16_t start_handle,
|
|
|
|
uint16_t end_handle,
|
|
|
|
esp_bt_uuid_t *incl_uuid,
|
|
|
|
esp_gattc_incl_svc_elem_t *result,
|
|
|
|
uint16_t *count);
|
|
|
|
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_attr_count(uint16_t conn_id,
|
|
|
|
esp_gatt_db_attr_type_t type,
|
|
|
|
uint16_t start_handle,
|
|
|
|
uint16_t end_handle,
|
|
|
|
uint16_t char_handle,
|
|
|
|
uint16_t *count);
|
|
|
|
|
|
|
|
esp_gatt_status_t btc_ble_gattc_get_db(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle,
|
|
|
|
esp_gattc_db_elem_t *db, uint16_t *count);
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-15 07:56:15 -05:00
|
|
|
|
|
|
|
#endif /* __BTC_GATTC_H__ */
|