blob: b105cba3d7a5a099ad4ac36a0e8a992d521d593e [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
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800108typedef struct {
109 register_server_callback register_server_cb;
110 connection_callback connection_cb;
111 service_added_callback service_added_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800112 service_stopped_callback service_stopped_cb;
113 service_deleted_callback service_deleted_cb;
Jakub Pawlowski26930022016-03-23 15:19:26 -0700114 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 Battafefb3342013-02-05 15:23:45 -0800118 request_exec_write_callback request_exec_write_cb;
119 response_confirmation_callback response_confirmation_cb;
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700120 indication_sent_callback indication_sent_cb;
121 congestion_callback congestion_cb;
Andre Eisenbach285fed02014-11-26 12:56:23 -0800122 mtu_changed_callback mtu_changed_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800123} btgatt_server_callbacks_t;
124
125/** Represents the standard BT-GATT server interface. */
126typedef 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 Battaf9f4d102014-04-18 10:02:49 -0700134 bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
135 bool is_direct, int transport);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800136
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 Radoslavov44d57d42016-12-09 17:55:30 -0800142 bt_status_t (*add_service)(int server_if, std::vector<btgatt_db_element_t> service);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800143
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 Pawlowski620fd712016-05-27 16:36:24 -0700152 int conn_id, int confirm,
Pavlin Radoslavov44d57d42016-12-09 17:55:30 -0800153 std::vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800154
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 Battaf9f4d102014-04-18 10:02:49 -0700158
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800159} btgatt_server_interface_t;
160
161__END_DECLS
162
163#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */