Home | History | Annotate | Download | only in hardware
      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 
     23 #include "bt_gatt_types.h"
     24 
     25 __BEGIN_DECLS
     26 
     27 /** GATT value type used in response to remote read requests */
     28 typedef struct
     29 {
     30     uint8_t           value[BTGATT_MAX_ATTR_LEN];
     31     uint16_t          handle;
     32     uint16_t          offset;
     33     uint16_t          len;
     34     uint8_t           auth_req;
     35 } btgatt_value_t;
     36 
     37 /** GATT remote read request response type */
     38 typedef union
     39 {
     40     btgatt_value_t attr_value;
     41     uint16_t            handle;
     42 } btgatt_response_t;
     43 
     44 /** BT-GATT Server callback structure. */
     45 
     46 /** Callback invoked in response to register_server */
     47 typedef void (*register_server_callback)(int status, int server_if,
     48                 bt_uuid_t *app_uuid);
     49 
     50 /** Callback indicating that a remote device has connected or been disconnected */
     51 typedef void (*connection_callback)(int conn_id, int server_if, int connected,
     52                                     bt_bdaddr_t *bda);
     53 
     54 /** Callback invoked in response to create_service */
     55 typedef void (*service_added_callback)(int status, int server_if,
     56                 btgatt_srvc_id_t *srvc_id, int srvc_handle);
     57 
     58 /** Callback indicating that an included service has been added to a service */
     59 typedef void (*included_service_added_callback)(int status, int server_if,
     60                 int srvc_handle, int incl_srvc_handle);
     61 
     62 /** Callback invoked when a characteristic has been added to a service */
     63 typedef void (*characteristic_added_callback)(int status, int server_if,
     64                 bt_uuid_t *uuid, int srvc_handle, int char_handle);
     65 
     66 /** Callback invoked when a descriptor has been added to a characteristic */
     67 typedef void (*descriptor_added_callback)(int status, int server_if,
     68                 bt_uuid_t *uuid, int srvc_handle, int descr_handle);
     69 
     70 /** Callback invoked in response to start_service */
     71 typedef void (*service_started_callback)(int status, int server_if,
     72                                          int srvc_handle);
     73 
     74 /** Callback invoked in response to stop_service */
     75 typedef void (*service_stopped_callback)(int status, int server_if,
     76                                          int srvc_handle);
     77 
     78 /** Callback triggered when a service has been deleted */
     79 typedef void (*service_deleted_callback)(int status, int server_if,
     80                                          int srvc_handle);
     81 
     82 /**
     83  * Callback invoked when a remote device has requested to read a characteristic
     84  * or descriptor. The application must respond by calling send_response
     85  */
     86 typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
     87                                       int attr_handle, int offset, bool is_long);
     88 
     89 /**
     90  * Callback invoked when a remote device has requested to write to a
     91  * characteristic or descriptor.
     92  */
     93 typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
     94                                        int attr_handle, int offset, int length,
     95                                        bool need_rsp, bool is_prep, uint8_t* value);
     96 
     97 /** Callback invoked when a previously prepared write is to be executed */
     98 typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
     99                                             bt_bdaddr_t *bda, int exec_write);
    100 
    101 /**
    102  * Callback triggered in response to send_response if the remote device
    103  * sends a confirmation.
    104  */
    105 typedef void (*response_confirmation_callback)(int status, int handle);
    106 
    107 /**
    108  * Callback confirming that a notification or indication has been sent
    109  * to a remote device.
    110  */
    111 typedef void (*indication_sent_callback)(int conn_id, int status);
    112 
    113 /**
    114  * Callback notifying an application that a remote device connection is currently congested
    115  * and cannot receive any more data. An application should avoid sending more data until
    116  * a further callback is received indicating the congestion status has been cleared.
    117  */
    118 typedef void (*congestion_callback)(int conn_id, bool congested);
    119 
    120 typedef struct {
    121     register_server_callback        register_server_cb;
    122     connection_callback             connection_cb;
    123     service_added_callback          service_added_cb;
    124     included_service_added_callback included_service_added_cb;
    125     characteristic_added_callback   characteristic_added_cb;
    126     descriptor_added_callback       descriptor_added_cb;
    127     service_started_callback        service_started_cb;
    128     service_stopped_callback        service_stopped_cb;
    129     service_deleted_callback        service_deleted_cb;
    130     request_read_callback           request_read_cb;
    131     request_write_callback          request_write_cb;
    132     request_exec_write_callback     request_exec_write_cb;
    133     response_confirmation_callback  response_confirmation_cb;
    134     indication_sent_callback        indication_sent_cb;
    135     congestion_callback             congestion_cb;
    136 } btgatt_server_callbacks_t;
    137 
    138 /** Represents the standard BT-GATT server interface. */
    139 typedef struct {
    140     /** Registers a GATT server application with the stack */
    141     bt_status_t (*register_server)( bt_uuid_t *uuid );
    142 
    143     /** Unregister a server application from the stack */
    144     bt_status_t (*unregister_server)(int server_if );
    145 
    146     /** Create a connection to a remote peripheral */
    147     bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
    148                             bool is_direct, int transport);
    149 
    150     /** Disconnect an established connection or cancel a pending one */
    151     bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
    152                     int conn_id );
    153 
    154     /** Create a new service */
    155     bt_status_t (*add_service)( int server_if, btgatt_srvc_id_t *srvc_id, int num_handles);
    156 
    157     /** Assign an included service to it's parent service */
    158     bt_status_t (*add_included_service)( int server_if, int service_handle, int included_handle);
    159 
    160     /** Add a characteristic to a service */
    161     bt_status_t (*add_characteristic)( int server_if,
    162                     int service_handle, bt_uuid_t *uuid,
    163                     int properties, int permissions);
    164 
    165     /** Add a descriptor to a given service */
    166     bt_status_t (*add_descriptor)(int server_if, int service_handle,
    167                                   bt_uuid_t *uuid, int permissions);
    168 
    169     /** Starts a local service */
    170     bt_status_t (*start_service)(int server_if, int service_handle,
    171                                  int transport);
    172 
    173     /** Stops a local service */
    174     bt_status_t (*stop_service)(int server_if, int service_handle);
    175 
    176     /** Delete a local service */
    177     bt_status_t (*delete_service)(int server_if, int service_handle);
    178 
    179     /** Send value indication to a remote device */
    180     bt_status_t (*send_indication)(int server_if, int attribute_handle,
    181                                    int conn_id, int len, int confirm,
    182                                    char* p_value);
    183 
    184     /** Send a response to a read/write operation */
    185     bt_status_t (*send_response)(int conn_id, int trans_id,
    186                                  int status, btgatt_response_t *response);
    187 
    188 } btgatt_server_interface_t;
    189 
    190 __END_DECLS
    191 
    192 #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */
    193