blob: 36259a189b08c8fe52fa39562d93cbaba104b82f [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
26__BEGIN_DECLS
27
28/** GATT value type used in response to remote read requests */
29typedef 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 */
39typedef 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 */
48typedef 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 Eisenbach33317182013-04-10 11:18:03 -070052typedef void (*connection_callback)(int conn_id, int server_if, int connected,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080053 bt_bdaddr_t *bda);
54
55/** Callback invoked in response to create_service */
56typedef void (*service_added_callback)(int status, int server_if,
Pavlin Radoslavov44d57d42016-12-09 17:55:30 -080057 std::vector<btgatt_db_element_t> service);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080058
59/** Callback invoked in response to stop_service */
60typedef void (*service_stopped_callback)(int status, int server_if,
61 int srvc_handle);
62
63/** Callback triggered when a service has been deleted */
64typedef 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 */
71typedef 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 */
78typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
Jakub Pawlowskidaaed0c2016-05-31 13:13:33 -070079 int attr_handle, int offset, bool need_rsp,
Pavlin Radoslavov44d57d42016-12-09 17:55:30 -080080 bool is_prep, std::vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080081
82/** Callback invoked when a previously prepared write is to be executed */
83typedef 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 */
90typedef void (*response_confirmation_callback)(int status, int handle);
91
Andre Eisenbach9ef3c722014-03-28 14:53:33 -070092/**
93 * Callback confirming that a notification or indication has been sent
94 * to a remote device.
95 */
96typedef 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 */
103typedef void (*congestion_callback)(int conn_id, bool congested);
104
Andre Eisenbach285fed02014-11-26 12:56:23 -0800105/** Callback invoked when the MTU for a given connection changes */
106typedef void (*mtu_changed_callback)(int conn_id, int mtu);
107
Jakub Pawlowskif3eb5582017-03-22 19:09:19 -0700108/** Callback invoked when the PHY for a given connection changes */
109typedef void (*phy_updated_callback)(int conn_id, uint8_t tx_phy,
110 uint8_t rx_phy, uint8_t status);
111
Jakub Pawlowski6f0c6f12017-03-23 18:13:12 -0700112/** Callback invoked when the connection parameters for a given connection changes */
113typedef void (*conn_updated_callback)(int conn_id, uint16_t interval,
114 uint16_t latency, uint16_t timeout,
115 uint8_t status);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800116typedef struct {
117 register_server_callback register_server_cb;
118 connection_callback connection_cb;
119 service_added_callback service_added_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800120 service_stopped_callback service_stopped_cb;
121 service_deleted_callback service_deleted_cb;
Jakub Pawlowski26930022016-03-23 15:19:26 -0700122 request_read_callback request_read_characteristic_cb;
123 request_read_callback request_read_descriptor_cb;
124 request_write_callback request_write_characteristic_cb;
125 request_write_callback request_write_descriptor_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800126 request_exec_write_callback request_exec_write_cb;
127 response_confirmation_callback response_confirmation_cb;
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700128 indication_sent_callback indication_sent_cb;
129 congestion_callback congestion_cb;
Andre Eisenbach285fed02014-11-26 12:56:23 -0800130 mtu_changed_callback mtu_changed_cb;
Jakub Pawlowskif3eb5582017-03-22 19:09:19 -0700131 phy_updated_callback phy_updated_cb;
Jakub Pawlowski6f0c6f12017-03-23 18:13:12 -0700132 conn_updated_callback conn_updated_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800133} btgatt_server_callbacks_t;
134
135/** Represents the standard BT-GATT server interface. */
136typedef struct {
137 /** Registers a GATT server application with the stack */
138 bt_status_t (*register_server)( bt_uuid_t *uuid );
139
140 /** Unregister a server application from the stack */
141 bt_status_t (*unregister_server)(int server_if );
142
143 /** Create a connection to a remote peripheral */
Ganesh Ganapathi Battaf9f4d102014-04-18 10:02:49 -0700144 bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
145 bool is_direct, int transport);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800146
147 /** Disconnect an established connection or cancel a pending one */
148 bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
149 int conn_id );
150
151 /** Create a new service */
Pavlin Radoslavov44d57d42016-12-09 17:55:30 -0800152 bt_status_t (*add_service)(int server_if, std::vector<btgatt_db_element_t> service);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800153
154 /** Stops a local service */
155 bt_status_t (*stop_service)(int server_if, int service_handle);
156
157 /** Delete a local service */
158 bt_status_t (*delete_service)(int server_if, int service_handle);
159
160 /** Send value indication to a remote device */
161 bt_status_t (*send_indication)(int server_if, int attribute_handle,
Jakub Pawlowski620fd712016-05-27 16:36:24 -0700162 int conn_id, int confirm,
Pavlin Radoslavov44d57d42016-12-09 17:55:30 -0800163 std::vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800164
165 /** Send a response to a read/write operation */
166 bt_status_t (*send_response)(int conn_id, int trans_id,
167 int status, btgatt_response_t *response);
Ganesh Ganapathi Battaf9f4d102014-04-18 10:02:49 -0700168
Jakub Pawlowskif3eb5582017-03-22 19:09:19 -0700169 bt_status_t (*set_preferred_phy)(int conn_id, uint8_t tx_phy,
170 uint8_t rx_phy, uint16_t phy_options);
171
172 bt_status_t (*read_phy)(
173 int conn_id,
174 base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)>
175 cb);
176
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800177} btgatt_server_interface_t;
178
179__END_DECLS
180
181#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */