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