blob: d2fdda3f4a4206329d2973a081f628cab55dbee0 [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,
59 btgatt_srvc_id_t *srvc_id, int srvc_handle);
60
61/** Callback indicating that an included service has been added to a service */
62typedef 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 */
66typedef 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 */
70typedef 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 */
74typedef void (*service_started_callback)(int status, int server_if,
75 int srvc_handle);
76
77/** Callback invoked in response to stop_service */
78typedef void (*service_stopped_callback)(int status, int server_if,
79 int srvc_handle);
80
81/** Callback triggered when a service has been deleted */
82typedef 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 */
89typedef 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 */
96typedef 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 */
101typedef 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 */
108typedef void (*response_confirmation_callback)(int status, int handle);
109
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700110/**
111 * Callback confirming that a notification or indication has been sent
112 * to a remote device.
113 */
114typedef 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 */
121typedef void (*congestion_callback)(int conn_id, bool congested);
122
Andre Eisenbach285fed02014-11-26 12:56:23 -0800123/** Callback invoked when the MTU for a given connection changes */
124typedef void (*mtu_changed_callback)(int conn_id, int mtu);
125
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800126typedef 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 Eisenbach9ef3c722014-03-28 14:53:33 -0700140 indication_sent_callback indication_sent_cb;
141 congestion_callback congestion_cb;
Andre Eisenbach285fed02014-11-26 12:56:23 -0800142 mtu_changed_callback mtu_changed_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800143} btgatt_server_callbacks_t;
144
145/** Represents the standard BT-GATT server interface. */
146typedef 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 Battaf9f4d102014-04-18 10:02:49 -0700154 bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
155 bool is_direct, int transport);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800156
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 Pawlowski620fd712016-05-27 16:36:24 -0700188 int conn_id, int confirm,
189 vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800190
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 Battaf9f4d102014-04-18 10:02:49 -0700194
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800195} btgatt_server_interface_t;
196
197__END_DECLS
198
199#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */