Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef ANDROID_INCLUDE_BT_GATT_CLIENT_H |
| 19 | #define ANDROID_INCLUDE_BT_GATT_CLIENT_H |
| 20 | |
| 21 | #include <stdint.h> |
Jakub Pawlowski | 620fd71 | 2016-05-27 16:36:24 -0700 | [diff] [blame] | 22 | #include <vector> |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 23 | #include "bt_gatt_types.h" |
Satya Calloji | a8b49d3 | 2015-02-10 09:20:07 -0800 | [diff] [blame] | 24 | #include "bt_common_types.h" |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 25 | |
| 26 | __BEGIN_DECLS |
| 27 | |
| 28 | /** |
| 29 | * Buffer sizes for maximum attribute length and maximum read/write |
| 30 | * operation buffer size. |
| 31 | */ |
| 32 | #define BTGATT_MAX_ATTR_LEN 600 |
| 33 | |
| 34 | /** Buffer type for unformatted reads/writes */ |
| 35 | typedef struct |
| 36 | { |
| 37 | uint8_t value[BTGATT_MAX_ATTR_LEN]; |
| 38 | uint16_t len; |
| 39 | } btgatt_unformatted_value_t; |
| 40 | |
| 41 | /** Parameters for GATT read operations */ |
| 42 | typedef struct |
| 43 | { |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 44 | uint16_t handle; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 45 | btgatt_unformatted_value_t value; |
| 46 | uint16_t value_type; |
| 47 | uint8_t status; |
| 48 | } btgatt_read_params_t; |
| 49 | |
| 50 | /** Parameters for GATT write operations */ |
| 51 | typedef struct |
| 52 | { |
| 53 | btgatt_srvc_id_t srvc_id; |
Andre Eisenbach | 02223d1 | 2013-07-09 00:02:48 -0700 | [diff] [blame] | 54 | btgatt_gatt_id_t char_id; |
| 55 | btgatt_gatt_id_t descr_id; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 56 | uint8_t status; |
| 57 | } btgatt_write_params_t; |
| 58 | |
| 59 | /** Attribute change notification parameters */ |
| 60 | typedef struct |
| 61 | { |
| 62 | uint8_t value[BTGATT_MAX_ATTR_LEN]; |
| 63 | bt_bdaddr_t bda; |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 64 | uint16_t handle; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 65 | uint16_t len; |
| 66 | uint8_t is_notify; |
| 67 | } btgatt_notify_params_t; |
| 68 | |
| 69 | typedef struct |
| 70 | { |
| 71 | bt_bdaddr_t *bda1; |
| 72 | bt_uuid_t *uuid1; |
| 73 | uint16_t u1; |
| 74 | uint16_t u2; |
| 75 | uint16_t u3; |
| 76 | uint16_t u4; |
| 77 | uint16_t u5; |
| 78 | } btgatt_test_params_t; |
| 79 | |
Satya Calloji | 5122502 | 2015-03-31 13:58:21 -0700 | [diff] [blame] | 80 | /* BT GATT client error codes */ |
| 81 | typedef enum |
| 82 | { |
| 83 | BT_GATTC_COMMAND_SUCCESS = 0, /* 0 Command succeeded */ |
| 84 | BT_GATTC_COMMAND_STARTED, /* 1 Command started OK. */ |
| 85 | BT_GATTC_COMMAND_BUSY, /* 2 Device busy with another command */ |
| 86 | BT_GATTC_COMMAND_STORED, /* 3 request is stored in control block */ |
| 87 | BT_GATTC_NO_RESOURCES, /* 4 No resources to issue command */ |
| 88 | BT_GATTC_MODE_UNSUPPORTED, /* 5 Request for 1 or more unsupported modes */ |
| 89 | BT_GATTC_ILLEGAL_VALUE, /* 6 Illegal command /parameter value */ |
| 90 | BT_GATTC_INCORRECT_STATE, /* 7 Device in wrong state for request */ |
| 91 | BT_GATTC_UNKNOWN_ADDR, /* 8 Unknown remote BD address */ |
| 92 | BT_GATTC_DEVICE_TIMEOUT, /* 9 Device timeout */ |
| 93 | BT_GATTC_INVALID_CONTROLLER_OUTPUT,/* 10 An incorrect value was received from HCI */ |
| 94 | BT_GATTC_SECURITY_ERROR, /* 11 Authorization or security failure or not authorized */ |
| 95 | BT_GATTC_DELAYED_ENCRYPTION_CHECK, /*12 Delayed encryption check */ |
| 96 | BT_GATTC_ERR_PROCESSING /* 12 Generic error */ |
| 97 | } btgattc_error_t; |
| 98 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 99 | /** BT-GATT Client callback structure. */ |
| 100 | |
| 101 | /** Callback invoked in response to register_client */ |
| 102 | typedef void (*register_client_callback)(int status, int client_if, |
| 103 | bt_uuid_t *app_uuid); |
| 104 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 105 | /** GATT open callback invoked in response to open */ |
| 106 | typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda); |
| 107 | |
| 108 | /** Callback invoked in response to close */ |
| 109 | typedef void (*disconnect_callback)(int conn_id, int status, |
| 110 | int client_if, bt_bdaddr_t* bda); |
| 111 | |
| 112 | /** |
| 113 | * Invoked in response to search_service when the GATT service search |
| 114 | * has been completed. |
| 115 | */ |
| 116 | typedef void (*search_complete_callback)(int conn_id, int status); |
| 117 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 118 | /** Callback invoked in response to [de]register_for_notification */ |
| 119 | typedef void (*register_for_notification_callback)(int conn_id, |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 120 | int registered, int status, uint16_t handle); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Remote device notification callback, invoked when a remote device sends |
| 124 | * a notification or indication that a client has registered for. |
| 125 | */ |
| 126 | typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data); |
| 127 | |
| 128 | /** Reports result of a GATT read operation */ |
| 129 | typedef void (*read_characteristic_callback)(int conn_id, int status, |
| 130 | btgatt_read_params_t *p_data); |
| 131 | |
| 132 | /** GATT write characteristic operation callback */ |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 133 | typedef void (*write_characteristic_callback)(int conn_id, int status, uint16_t handle); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 134 | |
| 135 | /** GATT execute prepared write callback */ |
| 136 | typedef void (*execute_write_callback)(int conn_id, int status); |
| 137 | |
| 138 | /** Callback invoked in response to read_descriptor */ |
| 139 | typedef void (*read_descriptor_callback)(int conn_id, int status, |
| 140 | btgatt_read_params_t *p_data); |
| 141 | |
| 142 | /** Callback invoked in response to write_descriptor */ |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 143 | typedef void (*write_descriptor_callback)(int conn_id, int status, uint16_t handle); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 144 | |
| 145 | /** Callback triggered in response to read_remote_rssi */ |
| 146 | typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda, |
| 147 | int rssi, int status); |
| 148 | |
Andre Eisenbach | 8a4b61a | 2014-03-25 06:30:05 -0700 | [diff] [blame] | 149 | /** Callback invoked when the MTU for a given connection changes */ |
| 150 | typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu); |
| 151 | |
Andre Eisenbach | 709f239 | 2013-12-16 16:16:54 -0800 | [diff] [blame] | 152 | |
Andre Eisenbach | 9ef3c72 | 2014-03-28 14:53:33 -0700 | [diff] [blame] | 153 | /** |
| 154 | * Callback notifying an application that a remote device connection is currently congested |
| 155 | * and cannot receive any more data. An application should avoid sending more data until |
| 156 | * a further callback is received indicating the congestion status has been cleared. |
| 157 | */ |
| 158 | typedef void (*congestion_callback)(int conn_id, bool congested); |
Satya Calloji | 5122502 | 2015-03-31 13:58:21 -0700 | [diff] [blame] | 159 | |
Jakub Pawlowski | f2e1352 | 2016-01-21 23:40:51 -0800 | [diff] [blame] | 160 | /** GATT get database callback */ |
| 161 | typedef void (*get_gatt_db_callback)(int conn_id, btgatt_db_element_t *db, int count); |
| 162 | |
Jakub Pawlowski | 83e598f | 2016-02-10 15:31:14 -0800 | [diff] [blame] | 163 | /** GATT services between start_handle and end_handle were removed */ |
| 164 | typedef void (*services_removed_callback)(int conn_id, uint16_t start_handle, uint16_t end_handle); |
| 165 | |
| 166 | /** GATT services were added */ |
| 167 | typedef void (*services_added_callback)(int conn_id, btgatt_db_element_t *added, int added_count); |
| 168 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 169 | typedef struct { |
| 170 | register_client_callback register_client_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 171 | connect_callback open_cb; |
| 172 | disconnect_callback close_cb; |
| 173 | search_complete_callback search_complete_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 174 | register_for_notification_callback register_for_notification_cb; |
| 175 | notify_callback notify_cb; |
| 176 | read_characteristic_callback read_characteristic_cb; |
| 177 | write_characteristic_callback write_characteristic_cb; |
| 178 | read_descriptor_callback read_descriptor_cb; |
| 179 | write_descriptor_callback write_descriptor_cb; |
| 180 | execute_write_callback execute_write_cb; |
| 181 | read_remote_rssi_callback read_remote_rssi_cb; |
Andre Eisenbach | 8a4b61a | 2014-03-25 06:30:05 -0700 | [diff] [blame] | 182 | configure_mtu_callback configure_mtu_cb; |
Andre Eisenbach | 9ef3c72 | 2014-03-28 14:53:33 -0700 | [diff] [blame] | 183 | congestion_callback congestion_cb; |
Jakub Pawlowski | f2e1352 | 2016-01-21 23:40:51 -0800 | [diff] [blame] | 184 | get_gatt_db_callback get_gatt_db_cb; |
Jakub Pawlowski | 83e598f | 2016-02-10 15:31:14 -0800 | [diff] [blame] | 185 | services_removed_callback services_removed_cb; |
| 186 | services_added_callback services_added_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 187 | } btgatt_client_callbacks_t; |
| 188 | |
| 189 | /** Represents the standard BT-GATT client interface. */ |
| 190 | |
| 191 | typedef struct { |
| 192 | /** Registers a GATT client application with the stack */ |
| 193 | bt_status_t (*register_client)( bt_uuid_t *uuid ); |
| 194 | |
| 195 | /** Unregister a client application from the stack */ |
| 196 | bt_status_t (*unregister_client)(int client_if ); |
| 197 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 198 | /** Create a connection to a remote LE or dual-mode device */ |
| 199 | bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr, |
Ganesh Ganapathi Batta | f9f4d10 | 2014-04-18 10:02:49 -0700 | [diff] [blame] | 200 | bool is_direct, int transport ); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 201 | |
| 202 | /** Disconnect a remote device or cancel a pending connection */ |
| 203 | bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr, |
| 204 | int conn_id); |
| 205 | |
| 206 | /** Clear the attribute cache for a given device */ |
| 207 | bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr ); |
| 208 | |
| 209 | /** |
| 210 | * Enumerate all GATT services on a connected device. |
| 211 | * Optionally, the results can be filtered for a given UUID. |
| 212 | */ |
| 213 | bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid ); |
| 214 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 215 | /** Read a characteristic on a remote device */ |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 216 | bt_status_t (*read_characteristic)( int conn_id, uint16_t handle, |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 217 | int auth_req ); |
| 218 | |
| 219 | /** Write a remote characteristic */ |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 220 | bt_status_t (*write_characteristic)(int conn_id, uint16_t handle, |
Jakub Pawlowski | 620fd71 | 2016-05-27 16:36:24 -0700 | [diff] [blame] | 221 | int write_type, int auth_req, |
Pavlin Radoslavov | 44d57d4 | 2016-12-09 17:55:30 -0800 | [diff] [blame] | 222 | std::vector<uint8_t> value); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 223 | |
| 224 | /** Read the descriptor for a given characteristic */ |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 225 | bt_status_t (*read_descriptor)(int conn_id, uint16_t handle, int auth_req); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 226 | |
| 227 | /** Write a remote descriptor for a given characteristic */ |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 228 | bt_status_t (*write_descriptor)( int conn_id, uint16_t handle, |
Pavlin Radoslavov | 44d57d4 | 2016-12-09 17:55:30 -0800 | [diff] [blame] | 229 | int auth_req, std::vector<uint8_t> value); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 230 | |
| 231 | /** Execute a prepared write operation */ |
| 232 | bt_status_t (*execute_write)(int conn_id, int execute); |
| 233 | |
| 234 | /** |
| 235 | * Register to receive notifications or indications for a given |
| 236 | * characteristic |
| 237 | */ |
| 238 | bt_status_t (*register_for_notification)( int client_if, |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 239 | const bt_bdaddr_t *bd_addr, uint16_t handle); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 240 | |
| 241 | /** Deregister a previous request for notifications/indications */ |
| 242 | bt_status_t (*deregister_for_notification)( int client_if, |
Jakub Pawlowski | 1d02bde | 2016-03-17 15:57:03 -0700 | [diff] [blame] | 243 | const bt_bdaddr_t *bd_addr, uint16_t handle); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 244 | |
| 245 | /** Request RSSI for a given remote device */ |
| 246 | bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr); |
| 247 | |
| 248 | /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */ |
| 249 | int (*get_device_type)( const bt_bdaddr_t *bd_addr ); |
| 250 | |
Andre Eisenbach | 8a4b61a | 2014-03-25 06:30:05 -0700 | [diff] [blame] | 251 | /** Configure the MTU for a given connection */ |
| 252 | bt_status_t (*configure_mtu)(int conn_id, int mtu); |
| 253 | |
Andre Eisenbach | da4eaca | 2014-07-16 22:58:36 -0700 | [diff] [blame] | 254 | /** Request a connection parameter update */ |
| 255 | bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval, |
| 256 | int max_interval, int latency, int timeout); |
| 257 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 258 | /** Test mode interface */ |
| 259 | bt_status_t (*test_command)( int command, btgatt_test_params_t* params); |
Ganesh Ganapathi Batta | f9f4d10 | 2014-04-18 10:02:49 -0700 | [diff] [blame] | 260 | |
Jakub Pawlowski | f2e1352 | 2016-01-21 23:40:51 -0800 | [diff] [blame] | 261 | /** Get gatt db content */ |
| 262 | bt_status_t (*get_gatt_db)( int conn_id); |
| 263 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 264 | } btgatt_client_interface_t; |
| 265 | |
| 266 | __END_DECLS |
| 267 | |
| 268 | #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */ |