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_SERVER_H |
| 19 | #define ANDROID_INCLUDE_BT_GATT_SERVER_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 | |
| 24 | #include "bt_gatt_types.h" |
| 25 | |
Jakub Pawlowski | 620fd71 | 2016-05-27 16:36:24 -0700 | [diff] [blame] | 26 | using std::vector; |
| 27 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 28 | __BEGIN_DECLS |
| 29 | |
| 30 | /** GATT value type used in response to remote read requests */ |
| 31 | typedef struct |
| 32 | { |
| 33 | uint8_t value[BTGATT_MAX_ATTR_LEN]; |
| 34 | uint16_t handle; |
| 35 | uint16_t offset; |
| 36 | uint16_t len; |
| 37 | uint8_t auth_req; |
| 38 | } btgatt_value_t; |
| 39 | |
| 40 | /** GATT remote read request response type */ |
| 41 | typedef union |
| 42 | { |
| 43 | btgatt_value_t attr_value; |
| 44 | uint16_t handle; |
| 45 | } btgatt_response_t; |
| 46 | |
| 47 | /** BT-GATT Server callback structure. */ |
| 48 | |
| 49 | /** Callback invoked in response to register_server */ |
| 50 | typedef void (*register_server_callback)(int status, int server_if, |
| 51 | bt_uuid_t *app_uuid); |
| 52 | |
| 53 | /** Callback indicating that a remote device has connected or been disconnected */ |
Andre Eisenbach | 3331718 | 2013-04-10 11:18:03 -0700 | [diff] [blame] | 54 | typedef void (*connection_callback)(int conn_id, int server_if, int connected, |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 55 | bt_bdaddr_t *bda); |
| 56 | |
| 57 | /** Callback invoked in response to create_service */ |
| 58 | typedef void (*service_added_callback)(int status, int server_if, |
| 59 | btgatt_srvc_id_t *srvc_id, int srvc_handle); |
| 60 | |
| 61 | /** Callback indicating that an included service has been added to a service */ |
| 62 | typedef void (*included_service_added_callback)(int status, int server_if, |
| 63 | int srvc_handle, int incl_srvc_handle); |
| 64 | |
| 65 | /** Callback invoked when a characteristic has been added to a service */ |
| 66 | typedef void (*characteristic_added_callback)(int status, int server_if, |
| 67 | bt_uuid_t *uuid, int srvc_handle, int char_handle); |
| 68 | |
| 69 | /** Callback invoked when a descriptor has been added to a characteristic */ |
| 70 | typedef void (*descriptor_added_callback)(int status, int server_if, |
| 71 | bt_uuid_t *uuid, int srvc_handle, int descr_handle); |
| 72 | |
| 73 | /** Callback invoked in response to start_service */ |
| 74 | typedef void (*service_started_callback)(int status, int server_if, |
| 75 | int srvc_handle); |
| 76 | |
| 77 | /** Callback invoked in response to stop_service */ |
| 78 | typedef void (*service_stopped_callback)(int status, int server_if, |
| 79 | int srvc_handle); |
| 80 | |
| 81 | /** Callback triggered when a service has been deleted */ |
| 82 | typedef void (*service_deleted_callback)(int status, int server_if, |
| 83 | int srvc_handle); |
| 84 | |
| 85 | /** |
| 86 | * Callback invoked when a remote device has requested to read a characteristic |
| 87 | * or descriptor. The application must respond by calling send_response |
| 88 | */ |
| 89 | typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda, |
| 90 | int attr_handle, int offset, bool is_long); |
| 91 | |
| 92 | /** |
| 93 | * Callback invoked when a remote device has requested to write to a |
| 94 | * characteristic or descriptor. |
| 95 | */ |
| 96 | typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda, |
| 97 | int attr_handle, int offset, int length, |
| 98 | bool need_rsp, bool is_prep, uint8_t* value); |
| 99 | |
| 100 | /** Callback invoked when a previously prepared write is to be executed */ |
| 101 | typedef void (*request_exec_write_callback)(int conn_id, int trans_id, |
| 102 | bt_bdaddr_t *bda, int exec_write); |
| 103 | |
| 104 | /** |
| 105 | * Callback triggered in response to send_response if the remote device |
| 106 | * sends a confirmation. |
| 107 | */ |
| 108 | typedef void (*response_confirmation_callback)(int status, int handle); |
| 109 | |
Andre Eisenbach | 9ef3c72 | 2014-03-28 14:53:33 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Callback confirming that a notification or indication has been sent |
| 112 | * to a remote device. |
| 113 | */ |
| 114 | typedef void (*indication_sent_callback)(int conn_id, int status); |
| 115 | |
| 116 | /** |
| 117 | * Callback notifying an application that a remote device connection is currently congested |
| 118 | * and cannot receive any more data. An application should avoid sending more data until |
| 119 | * a further callback is received indicating the congestion status has been cleared. |
| 120 | */ |
| 121 | typedef void (*congestion_callback)(int conn_id, bool congested); |
| 122 | |
Andre Eisenbach | 285fed0 | 2014-11-26 12:56:23 -0800 | [diff] [blame] | 123 | /** Callback invoked when the MTU for a given connection changes */ |
| 124 | typedef void (*mtu_changed_callback)(int conn_id, int mtu); |
| 125 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 126 | typedef struct { |
| 127 | register_server_callback register_server_cb; |
| 128 | connection_callback connection_cb; |
| 129 | service_added_callback service_added_cb; |
| 130 | included_service_added_callback included_service_added_cb; |
| 131 | characteristic_added_callback characteristic_added_cb; |
| 132 | descriptor_added_callback descriptor_added_cb; |
| 133 | service_started_callback service_started_cb; |
| 134 | service_stopped_callback service_stopped_cb; |
| 135 | service_deleted_callback service_deleted_cb; |
| 136 | request_read_callback request_read_cb; |
| 137 | request_write_callback request_write_cb; |
| 138 | request_exec_write_callback request_exec_write_cb; |
| 139 | response_confirmation_callback response_confirmation_cb; |
Andre Eisenbach | 9ef3c72 | 2014-03-28 14:53:33 -0700 | [diff] [blame] | 140 | indication_sent_callback indication_sent_cb; |
| 141 | congestion_callback congestion_cb; |
Andre Eisenbach | 285fed0 | 2014-11-26 12:56:23 -0800 | [diff] [blame] | 142 | mtu_changed_callback mtu_changed_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 143 | } btgatt_server_callbacks_t; |
| 144 | |
| 145 | /** Represents the standard BT-GATT server interface. */ |
| 146 | typedef struct { |
| 147 | /** Registers a GATT server application with the stack */ |
| 148 | bt_status_t (*register_server)( bt_uuid_t *uuid ); |
| 149 | |
| 150 | /** Unregister a server application from the stack */ |
| 151 | bt_status_t (*unregister_server)(int server_if ); |
| 152 | |
| 153 | /** Create a connection to a remote peripheral */ |
Ganesh Ganapathi Batta | f9f4d10 | 2014-04-18 10:02:49 -0700 | [diff] [blame] | 154 | bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr, |
| 155 | bool is_direct, int transport); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 156 | |
| 157 | /** Disconnect an established connection or cancel a pending one */ |
| 158 | bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr, |
| 159 | int conn_id ); |
| 160 | |
| 161 | /** Create a new service */ |
| 162 | bt_status_t (*add_service)( int server_if, btgatt_srvc_id_t *srvc_id, int num_handles); |
| 163 | |
| 164 | /** Assign an included service to it's parent service */ |
| 165 | bt_status_t (*add_included_service)( int server_if, int service_handle, int included_handle); |
| 166 | |
| 167 | /** Add a characteristic to a service */ |
| 168 | bt_status_t (*add_characteristic)( int server_if, |
| 169 | int service_handle, bt_uuid_t *uuid, |
| 170 | int properties, int permissions); |
| 171 | |
| 172 | /** Add a descriptor to a given service */ |
| 173 | bt_status_t (*add_descriptor)(int server_if, int service_handle, |
| 174 | bt_uuid_t *uuid, int permissions); |
| 175 | |
| 176 | /** Starts a local service */ |
| 177 | bt_status_t (*start_service)(int server_if, int service_handle, |
| 178 | int transport); |
| 179 | |
| 180 | /** Stops a local service */ |
| 181 | bt_status_t (*stop_service)(int server_if, int service_handle); |
| 182 | |
| 183 | /** Delete a local service */ |
| 184 | bt_status_t (*delete_service)(int server_if, int service_handle); |
| 185 | |
| 186 | /** Send value indication to a remote device */ |
| 187 | bt_status_t (*send_indication)(int server_if, int attribute_handle, |
Jakub Pawlowski | 620fd71 | 2016-05-27 16:36:24 -0700 | [diff] [blame] | 188 | int conn_id, int confirm, |
| 189 | vector<uint8_t> value); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 190 | |
| 191 | /** Send a response to a read/write operation */ |
| 192 | bt_status_t (*send_response)(int conn_id, int trans_id, |
| 193 | int status, btgatt_response_t *response); |
Ganesh Ganapathi Batta | f9f4d10 | 2014-04-18 10:02:49 -0700 | [diff] [blame] | 194 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 195 | } btgatt_server_interface_t; |
| 196 | |
| 197 | __END_DECLS |
| 198 | |
| 199 | #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */ |