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, |
Jakub Pawlowski | 2693002 | 2016-03-23 15:19:26 -0700 | [diff] [blame] | 59 | vector<btgatt_db_element_t> service); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 60 | |
| 61 | /** Callback invoked in response to stop_service */ |
| 62 | typedef void (*service_stopped_callback)(int status, int server_if, |
| 63 | int srvc_handle); |
| 64 | |
| 65 | /** Callback triggered when a service has been deleted */ |
| 66 | typedef void (*service_deleted_callback)(int status, int server_if, |
| 67 | int srvc_handle); |
| 68 | |
| 69 | /** |
| 70 | * Callback invoked when a remote device has requested to read a characteristic |
| 71 | * or descriptor. The application must respond by calling send_response |
| 72 | */ |
| 73 | typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda, |
| 74 | int attr_handle, int offset, bool is_long); |
| 75 | |
| 76 | /** |
| 77 | * Callback invoked when a remote device has requested to write to a |
| 78 | * characteristic or descriptor. |
| 79 | */ |
| 80 | typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda, |
Jakub Pawlowski | daaed0c | 2016-05-31 13:13:33 -0700 | [diff] [blame] | 81 | int attr_handle, int offset, bool need_rsp, |
| 82 | bool is_prep, vector<uint8_t> value); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 83 | |
| 84 | /** Callback invoked when a previously prepared write is to be executed */ |
| 85 | typedef void (*request_exec_write_callback)(int conn_id, int trans_id, |
| 86 | bt_bdaddr_t *bda, int exec_write); |
| 87 | |
| 88 | /** |
| 89 | * Callback triggered in response to send_response if the remote device |
| 90 | * sends a confirmation. |
| 91 | */ |
| 92 | typedef void (*response_confirmation_callback)(int status, int handle); |
| 93 | |
Andre Eisenbach | 9ef3c72 | 2014-03-28 14:53:33 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Callback confirming that a notification or indication has been sent |
| 96 | * to a remote device. |
| 97 | */ |
| 98 | typedef void (*indication_sent_callback)(int conn_id, int status); |
| 99 | |
| 100 | /** |
| 101 | * Callback notifying an application that a remote device connection is currently congested |
| 102 | * and cannot receive any more data. An application should avoid sending more data until |
| 103 | * a further callback is received indicating the congestion status has been cleared. |
| 104 | */ |
| 105 | typedef void (*congestion_callback)(int conn_id, bool congested); |
| 106 | |
Andre Eisenbach | 285fed0 | 2014-11-26 12:56:23 -0800 | [diff] [blame] | 107 | /** Callback invoked when the MTU for a given connection changes */ |
| 108 | typedef void (*mtu_changed_callback)(int conn_id, int mtu); |
| 109 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 110 | typedef struct { |
| 111 | register_server_callback register_server_cb; |
| 112 | connection_callback connection_cb; |
| 113 | service_added_callback service_added_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 114 | service_stopped_callback service_stopped_cb; |
| 115 | service_deleted_callback service_deleted_cb; |
Jakub Pawlowski | 2693002 | 2016-03-23 15:19:26 -0700 | [diff] [blame] | 116 | request_read_callback request_read_characteristic_cb; |
| 117 | request_read_callback request_read_descriptor_cb; |
| 118 | request_write_callback request_write_characteristic_cb; |
| 119 | request_write_callback request_write_descriptor_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 120 | request_exec_write_callback request_exec_write_cb; |
| 121 | response_confirmation_callback response_confirmation_cb; |
Andre Eisenbach | 9ef3c72 | 2014-03-28 14:53:33 -0700 | [diff] [blame] | 122 | indication_sent_callback indication_sent_cb; |
| 123 | congestion_callback congestion_cb; |
Andre Eisenbach | 285fed0 | 2014-11-26 12:56:23 -0800 | [diff] [blame] | 124 | mtu_changed_callback mtu_changed_cb; |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 125 | } btgatt_server_callbacks_t; |
| 126 | |
| 127 | /** Represents the standard BT-GATT server interface. */ |
| 128 | typedef struct { |
| 129 | /** Registers a GATT server application with the stack */ |
| 130 | bt_status_t (*register_server)( bt_uuid_t *uuid ); |
| 131 | |
| 132 | /** Unregister a server application from the stack */ |
| 133 | bt_status_t (*unregister_server)(int server_if ); |
| 134 | |
| 135 | /** Create a connection to a remote peripheral */ |
Ganesh Ganapathi Batta | f9f4d10 | 2014-04-18 10:02:49 -0700 | [diff] [blame] | 136 | bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr, |
| 137 | bool is_direct, int transport); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 138 | |
| 139 | /** Disconnect an established connection or cancel a pending one */ |
| 140 | bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr, |
| 141 | int conn_id ); |
| 142 | |
| 143 | /** Create a new service */ |
Jakub Pawlowski | 2693002 | 2016-03-23 15:19:26 -0700 | [diff] [blame] | 144 | bt_status_t (*add_service)(int server_if, vector<btgatt_db_element_t> service); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 145 | |
| 146 | /** Stops a local service */ |
| 147 | bt_status_t (*stop_service)(int server_if, int service_handle); |
| 148 | |
| 149 | /** Delete a local service */ |
| 150 | bt_status_t (*delete_service)(int server_if, int service_handle); |
| 151 | |
| 152 | /** Send value indication to a remote device */ |
| 153 | bt_status_t (*send_indication)(int server_if, int attribute_handle, |
Jakub Pawlowski | 620fd71 | 2016-05-27 16:36:24 -0700 | [diff] [blame] | 154 | int conn_id, int confirm, |
| 155 | vector<uint8_t> value); |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 156 | |
| 157 | /** Send a response to a read/write operation */ |
| 158 | bt_status_t (*send_response)(int conn_id, int trans_id, |
| 159 | int status, btgatt_response_t *response); |
Ganesh Ganapathi Batta | f9f4d10 | 2014-04-18 10:02:49 -0700 | [diff] [blame] | 160 | |
Ganesh Ganapathi Batta | fefb334 | 2013-02-05 15:23:45 -0800 | [diff] [blame] | 161 | } btgatt_server_interface_t; |
| 162 | |
| 163 | __END_DECLS |
| 164 | |
| 165 | #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */ |