bt_gatt_server.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* SPDX-License-Identifier: Apache-2.0 */
  2. /*
  3. * Copyright (C) 2013 The Android Open Source Project
  4. *
  5. */
  6. #ifndef ANDROID_INCLUDE_BT_GATT_SERVER_H
  7. #define ANDROID_INCLUDE_BT_GATT_SERVER_H
  8. #include <stdint.h>
  9. #include "bt_gatt_types.h"
  10. __BEGIN_DECLS
  11. /** GATT value type used in response to remote read requests */
  12. typedef struct
  13. {
  14. uint8_t value[BTGATT_MAX_ATTR_LEN];
  15. uint16_t handle;
  16. uint16_t offset;
  17. uint16_t len;
  18. uint8_t auth_req;
  19. } btgatt_value_t;
  20. /** GATT remote read request response type */
  21. typedef union
  22. {
  23. btgatt_value_t attr_value;
  24. uint16_t handle;
  25. } btgatt_response_t;
  26. /** BT-GATT Server callback structure. */
  27. /** Callback invoked in response to register_server */
  28. typedef void (*register_server_callback)(int status, int server_if,
  29. bt_uuid_t *app_uuid);
  30. /** Callback indicating that a remote device has connected or been disconnected */
  31. typedef void (*connection_callback)(int conn_id, int server_if, int connected,
  32. bt_bdaddr_t *bda);
  33. /** Callback invoked in response to create_service */
  34. typedef void (*service_added_callback)(int status, int server_if,
  35. btgatt_srvc_id_t *srvc_id, int srvc_handle);
  36. /** Callback indicating that an included service has been added to a service */
  37. typedef void (*included_service_added_callback)(int status, int server_if,
  38. int srvc_handle, int incl_srvc_handle);
  39. /** Callback invoked when a characteristic has been added to a service */
  40. typedef void (*characteristic_added_callback)(int status, int server_if,
  41. bt_uuid_t *uuid, int srvc_handle, int char_handle);
  42. /** Callback invoked when a descriptor has been added to a characteristic */
  43. typedef void (*descriptor_added_callback)(int status, int server_if,
  44. bt_uuid_t *uuid, int srvc_handle, int descr_handle);
  45. /** Callback invoked in response to start_service */
  46. typedef void (*service_started_callback)(int status, int server_if,
  47. int srvc_handle);
  48. /** Callback invoked in response to stop_service */
  49. typedef void (*service_stopped_callback)(int status, int server_if,
  50. int srvc_handle);
  51. /** Callback triggered when a service has been deleted */
  52. typedef void (*service_deleted_callback)(int status, int server_if,
  53. int srvc_handle);
  54. /**
  55. * Callback invoked when a remote device has requested to read a characteristic
  56. * or descriptor. The application must respond by calling send_response
  57. */
  58. typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
  59. int attr_handle, int offset, bool is_long);
  60. /**
  61. * Callback invoked when a remote device has requested to write to a
  62. * characteristic or descriptor.
  63. */
  64. typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
  65. int attr_handle, int offset, int length,
  66. bool need_rsp, bool is_prep, uint8_t* value);
  67. /** Callback invoked when a previously prepared write is to be executed */
  68. typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
  69. bt_bdaddr_t *bda, int exec_write);
  70. /**
  71. * Callback triggered in response to send_response if the remote device
  72. * sends a confirmation.
  73. */
  74. typedef void (*response_confirmation_callback)(int status, int handle);
  75. /**
  76. * Callback confirming that a notification or indication has been sent
  77. * to a remote device.
  78. */
  79. typedef void (*indication_sent_callback)(int conn_id, int status);
  80. /**
  81. * Callback notifying an application that a remote device connection is currently congested
  82. * and cannot receive any more data. An application should avoid sending more data until
  83. * a further callback is received indicating the congestion status has been cleared.
  84. */
  85. typedef void (*congestion_callback)(int conn_id, bool congested);
  86. /** Callback invoked when the MTU for a given connection changes */
  87. typedef void (*mtu_changed_callback)(int conn_id, int mtu);
  88. typedef struct {
  89. register_server_callback register_server_cb;
  90. connection_callback connection_cb;
  91. service_added_callback service_added_cb;
  92. included_service_added_callback included_service_added_cb;
  93. characteristic_added_callback characteristic_added_cb;
  94. descriptor_added_callback descriptor_added_cb;
  95. service_started_callback service_started_cb;
  96. service_stopped_callback service_stopped_cb;
  97. service_deleted_callback service_deleted_cb;
  98. request_read_callback request_read_cb;
  99. request_write_callback request_write_cb;
  100. request_exec_write_callback request_exec_write_cb;
  101. response_confirmation_callback response_confirmation_cb;
  102. indication_sent_callback indication_sent_cb;
  103. congestion_callback congestion_cb;
  104. mtu_changed_callback mtu_changed_cb;
  105. } btgatt_server_callbacks_t;
  106. /** Represents the standard BT-GATT server interface. */
  107. typedef struct {
  108. /** Registers a GATT server application with the stack */
  109. bt_status_t (*register_server)( bt_uuid_t *uuid );
  110. /** Unregister a server application from the stack */
  111. bt_status_t (*unregister_server)(int server_if );
  112. /** Create a connection to a remote peripheral */
  113. bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
  114. bool is_direct, int transport);
  115. /** Disconnect an established connection or cancel a pending one */
  116. bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
  117. int conn_id );
  118. /** Create a new service */
  119. bt_status_t (*add_service)( int server_if, btgatt_srvc_id_t *srvc_id, int num_handles);
  120. /** Assign an included service to it's parent service */
  121. bt_status_t (*add_included_service)( int server_if, int service_handle, int included_handle);
  122. /** Add a characteristic to a service */
  123. bt_status_t (*add_characteristic)( int server_if,
  124. int service_handle, bt_uuid_t *uuid,
  125. int properties, int permissions);
  126. /** Add a descriptor to a given service */
  127. bt_status_t (*add_descriptor)(int server_if, int service_handle,
  128. bt_uuid_t *uuid, int permissions);
  129. /** Starts a local service */
  130. bt_status_t (*start_service)(int server_if, int service_handle,
  131. int transport);
  132. /** Stops a local service */
  133. bt_status_t (*stop_service)(int server_if, int service_handle);
  134. /** Delete a local service */
  135. bt_status_t (*delete_service)(int server_if, int service_handle);
  136. /** Send value indication to a remote device */
  137. bt_status_t (*send_indication)(int server_if, int attribute_handle,
  138. int conn_id, int len, int confirm,
  139. char* p_value);
  140. /** Send a response to a read/write operation */
  141. bt_status_t (*send_response)(int conn_id, int trans_id,
  142. int status, btgatt_response_t *response);
  143. } btgatt_server_interface_t;
  144. __END_DECLS
  145. #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */