bt_gatt_server.h
Go to the documentation of this file.
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>
22 #include <vector>
23 
24 #include "bt_gatt_types.h"
25 
26 using std::vector;
27 
28 __BEGIN_DECLS
29 
30 /** GATT value type used in response to remote read requests */
31 typedef 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;
39 
40 /** GATT remote read request response type */
41 typedef union
42 {
44  uint16_t handle;
46 
47 /** BT-GATT Server callback structure. */
48 
49 /** Callback invoked in response to register_server */
50 typedef 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 */
54 typedef void (*connection_callback)(int conn_id, int server_if, int connected,
55  bt_bdaddr_t *bda);
56 
57 /** Callback invoked in response to create_service */
58 typedef 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 */
62 typedef 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 */
66 typedef 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 */
70 typedef 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 */
74 typedef void (*service_started_callback)(int status, int server_if,
75  int srvc_handle);
76 
77 /** Callback invoked in response to stop_service */
78 typedef void (*service_stopped_callback)(int status, int server_if,
79  int srvc_handle);
80 
81 /** Callback triggered when a service has been deleted */
82 typedef 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  */
89 typedef 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  */
96 typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
97  int attr_handle, int offset, bool need_rsp,
98  bool is_prep, vector<uint8_t> value);
99 
100 /** Callback invoked when a previously prepared write is to be executed */
101 typedef 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  */
108 typedef void (*response_confirmation_callback)(int status, int handle);
109 
110 /**
111  * Callback confirming that a notification or indication has been sent
112  * to a remote device.
113  */
114 typedef 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  */
121 typedef void (*congestion_callback)(int conn_id, bool congested);
122 
123 /** Callback invoked when the MTU for a given connection changes */
124 typedef void (*mtu_changed_callback)(int conn_id, int mtu);
125 
126 typedef struct {
144 
145 /** Represents the standard BT-GATT server interface. */
146 typedef 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 */
154  bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
155  bool is_direct, int transport);
156 
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,
188  int conn_id, int confirm,
189  vector<uint8_t> value);
190 
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);
194 
196 
197 __END_DECLS
198 
199 #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */
void(* service_added_callback)(int status, int server_if, btgatt_srvc_id_t *srvc_id, int srvc_handle)
void(* included_service_added_callback)(int status, int server_if, int srvc_handle, int incl_srvc_handle)
void(* response_confirmation_callback)(int status, int handle)
void(* request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda, int attr_handle, int offset, bool need_rsp, bool is_prep, vector< uint8_t > value)
void(* register_server_callback)(int status, int server_if, bt_uuid_t *app_uuid)
service_started_callback service_started_cb
descriptor_added_callback descriptor_added_cb
register_server_callback register_server_cb
request_exec_write_callback request_exec_write_cb
void(* characteristic_added_callback)(int status, int server_if, bt_uuid_t *uuid, int srvc_handle, int char_handle)
characteristic_added_callback characteristic_added_cb
request_write_callback request_write_cb
included_service_added_callback included_service_added_cb
#define BTGATT_MAX_ATTR_LEN
void(* indication_sent_callback)(int conn_id, int status)
bt_status_t
Definition: bluetooth.h:80
void(* mtu_changed_callback)(int conn_id, int mtu)
void(* request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda, int attr_handle, int offset, bool is_long)
response_confirmation_callback response_confirmation_cb
service_added_callback service_added_cb
service_deleted_callback service_deleted_cb
request_read_callback request_read_cb
void(* request_exec_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda, int exec_write)
void(* congestion_callback)(int conn_id, bool congested)
void(* descriptor_added_callback)(int status, int server_if, bt_uuid_t *uuid, int srvc_handle, int descr_handle)
void(* connection_callback)(int conn_id, int server_if, int connected, bt_bdaddr_t *bda)
connection_callback connection_cb
service_stopped_callback service_stopped_cb
void(* service_started_callback)(int status, int server_if, int srvc_handle)
congestion_callback congestion_cb
void(* service_deleted_callback)(int status, int server_if, int srvc_handle)
void(* service_stopped_callback)(int status, int server_if, int srvc_handle)
btgatt_value_t attr_value
indication_sent_callback indication_sent_cb
mtu_changed_callback mtu_changed_cb