blob: 92af285eaa2d3e9cddfd301dddf21c63892bfaba [file] [log] [blame]
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -08001/*
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 Pawlowski620fd712016-05-27 16:36:24 -070022#include <vector>
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080023
24#include "bt_gatt_types.h"
25
Jakub Pawlowski620fd712016-05-27 16:36:24 -070026using std::vector;
27
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080028__BEGIN_DECLS
29
30/** GATT value type used in response to remote read requests */
31typedef 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 */
41typedef 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 */
50typedef 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 Eisenbach33317182013-04-10 11:18:03 -070054typedef void (*connection_callback)(int conn_id, int server_if, int connected,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080055 bt_bdaddr_t *bda);
56
57/** Callback invoked in response to create_service */
58typedef void (*service_added_callback)(int status, int server_if,
Jakub Pawlowski26930022016-03-23 15:19:26 -070059 vector<btgatt_db_element_t> service);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080060
61/** Callback invoked in response to stop_service */
62typedef void (*service_stopped_callback)(int status, int server_if,
63 int srvc_handle);
64
65/** Callback triggered when a service has been deleted */
66typedef 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 */
73typedef 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 */
80typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
Jakub Pawlowskidaaed0c2016-05-31 13:13:33 -070081 int attr_handle, int offset, bool need_rsp,
82 bool is_prep, vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080083
84/** Callback invoked when a previously prepared write is to be executed */
85typedef 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 */
92typedef void (*response_confirmation_callback)(int status, int handle);
93
Andre Eisenbach9ef3c722014-03-28 14:53:33 -070094/**
95 * Callback confirming that a notification or indication has been sent
96 * to a remote device.
97 */
98typedef 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 */
105typedef void (*congestion_callback)(int conn_id, bool congested);
106
Andre Eisenbach285fed02014-11-26 12:56:23 -0800107/** Callback invoked when the MTU for a given connection changes */
108typedef void (*mtu_changed_callback)(int conn_id, int mtu);
109
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800110typedef struct {
111 register_server_callback register_server_cb;
112 connection_callback connection_cb;
113 service_added_callback service_added_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800114 service_stopped_callback service_stopped_cb;
115 service_deleted_callback service_deleted_cb;
Jakub Pawlowski26930022016-03-23 15:19:26 -0700116 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 Battafefb3342013-02-05 15:23:45 -0800120 request_exec_write_callback request_exec_write_cb;
121 response_confirmation_callback response_confirmation_cb;
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700122 indication_sent_callback indication_sent_cb;
123 congestion_callback congestion_cb;
Andre Eisenbach285fed02014-11-26 12:56:23 -0800124 mtu_changed_callback mtu_changed_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800125} btgatt_server_callbacks_t;
126
127/** Represents the standard BT-GATT server interface. */
128typedef 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 Battaf9f4d102014-04-18 10:02:49 -0700136 bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
137 bool is_direct, int transport);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800138
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 Pawlowski26930022016-03-23 15:19:26 -0700144 bt_status_t (*add_service)(int server_if, vector<btgatt_db_element_t> service);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800145
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 Pawlowski620fd712016-05-27 16:36:24 -0700154 int conn_id, int confirm,
155 vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800156
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 Battaf9f4d102014-04-18 10:02:49 -0700160
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800161} btgatt_server_interface_t;
162
163__END_DECLS
164
165#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */