Home | History | Annotate | Download | only in gatt
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2003-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  This is the private file for the BTA GATT server.
     22  *
     23  ******************************************************************************/
     24 #ifndef BTA_GATTS_INT_H
     25 #define BTA_GATTS_INT_H
     26 
     27 #include "bt_target.h"
     28 #include "bta_gatt_api.h"
     29 #include "bta_sys.h"
     30 #include "gatt_api.h"
     31 
     32 #include "bt_common.h"
     33 
     34 /*****************************************************************************
     35  *  Constants and data types
     36  ****************************************************************************/
     37 enum {
     38   BTA_GATTS_API_REG_EVT = BTA_SYS_EVT_START(BTA_ID_GATTS),
     39   BTA_GATTS_INT_START_IF_EVT,
     40   BTA_GATTS_API_DEREG_EVT,
     41   BTA_GATTS_API_INDICATION_EVT,
     42 
     43   BTA_GATTS_API_DEL_SRVC_EVT,
     44   BTA_GATTS_API_STOP_SRVC_EVT,
     45   BTA_GATTS_API_RSP_EVT,
     46   BTA_GATTS_API_OPEN_EVT,
     47   BTA_GATTS_API_CANCEL_OPEN_EVT,
     48   BTA_GATTS_API_CLOSE_EVT,
     49   BTA_GATTS_API_DISABLE_EVT
     50 };
     51 typedef uint16_t tBTA_GATTS_INT_EVT;
     52 
     53 /* max number of application allowed on device */
     54 #define BTA_GATTS_MAX_APP_NUM GATT_MAX_SR_PROFILES
     55 
     56 /* max number of services allowed in the device */
     57 #define BTA_GATTS_MAX_SRVC_NUM GATT_MAX_SR_PROFILES
     58 
     59 /* internal strucutre for GATTC register API  */
     60 typedef struct {
     61   BT_HDR hdr;
     62   tBT_UUID app_uuid;
     63   tBTA_GATTS_CBACK* p_cback;
     64 } tBTA_GATTS_API_REG;
     65 
     66 typedef struct {
     67   BT_HDR hdr;
     68   tBTA_GATTS_IF server_if;
     69 } tBTA_GATTS_INT_START_IF;
     70 
     71 typedef tBTA_GATTS_INT_START_IF tBTA_GATTS_API_DEREG;
     72 
     73 typedef struct {
     74   BT_HDR hdr;
     75   tBTA_GATTS_IF server_if;
     76   btgatt_db_element_t* service;
     77   uint16_t count;
     78 } tBTA_GATTS_API_ADD_SERVICE;
     79 
     80 typedef struct {
     81   BT_HDR hdr;
     82   uint16_t attr_id;
     83   uint16_t len;
     84   bool need_confirm;
     85   uint8_t value[BTA_GATT_MAX_ATTR_LEN];
     86 } tBTA_GATTS_API_INDICATION;
     87 
     88 typedef struct {
     89   BT_HDR hdr;
     90   uint32_t trans_id;
     91   tBTA_GATT_STATUS status;
     92   tBTA_GATTS_RSP* p_rsp;
     93 } tBTA_GATTS_API_RSP;
     94 
     95 typedef struct {
     96   BT_HDR hdr;
     97   tBTA_GATT_TRANSPORT transport;
     98 } tBTA_GATTS_API_START;
     99 
    100 typedef struct {
    101   BT_HDR hdr;
    102   RawAddress remote_bda;
    103   tBTA_GATTS_IF server_if;
    104   bool is_direct;
    105   tBTA_GATT_TRANSPORT transport;
    106 
    107 } tBTA_GATTS_API_OPEN;
    108 
    109 typedef tBTA_GATTS_API_OPEN tBTA_GATTS_API_CANCEL_OPEN;
    110 
    111 typedef union {
    112   BT_HDR hdr;
    113   tBTA_GATTS_API_REG api_reg;
    114   tBTA_GATTS_API_DEREG api_dereg;
    115   tBTA_GATTS_API_ADD_SERVICE api_add_service;
    116   tBTA_GATTS_API_INDICATION api_indicate;
    117   tBTA_GATTS_API_RSP api_rsp;
    118   tBTA_GATTS_API_OPEN api_open;
    119   tBTA_GATTS_API_CANCEL_OPEN api_cancel_open;
    120 
    121   tBTA_GATTS_INT_START_IF int_start_if;
    122 } tBTA_GATTS_DATA;
    123 
    124 /* application registration control block */
    125 typedef struct {
    126   bool in_use;
    127   tBT_UUID app_uuid;
    128   tBTA_GATTS_CBACK* p_cback;
    129   tBTA_GATTS_IF gatt_if;
    130 } tBTA_GATTS_RCB;
    131 
    132 /* service registration control block */
    133 typedef struct {
    134   tBT_UUID service_uuid; /* service UUID */
    135   uint16_t service_id;   /* service start handle */
    136   uint8_t rcb_idx;
    137   uint8_t idx; /* self index of serviec CB */
    138   bool in_use;
    139 } tBTA_GATTS_SRVC_CB;
    140 
    141 /* GATT server control block */
    142 typedef struct {
    143   bool enabled;
    144   tBTA_GATTS_RCB rcb[BTA_GATTS_MAX_APP_NUM];
    145   tBTA_GATTS_SRVC_CB srvc_cb[BTA_GATTS_MAX_SRVC_NUM];
    146 } tBTA_GATTS_CB;
    147 
    148 /*****************************************************************************
    149  *  Global data
    150  ****************************************************************************/
    151 
    152 /* GATTC control block */
    153 extern tBTA_GATTS_CB bta_gatts_cb;
    154 
    155 /*****************************************************************************
    156  *  Function prototypes
    157  ****************************************************************************/
    158 extern bool bta_gatts_hdl_event(BT_HDR* p_msg);
    159 
    160 extern void bta_gatts_api_disable(tBTA_GATTS_CB* p_cb);
    161 extern void bta_gatts_api_enable(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_data);
    162 extern void bta_gatts_register(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
    163 extern void bta_gatts_start_if(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
    164 extern void bta_gatts_deregister(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
    165 extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB* p_srvc_cb,
    166                                      tBTA_GATTS_DATA* p_msg);
    167 extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB* p_srvc_cb,
    168                                    tBTA_GATTS_DATA* p_msg);
    169 
    170 extern void bta_gatts_send_rsp(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
    171 extern void bta_gatts_indicate_handle(tBTA_GATTS_CB* p_cb,
    172                                       tBTA_GATTS_DATA* p_msg);
    173 
    174 extern void bta_gatts_open(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
    175 extern void bta_gatts_cancel_open(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
    176 extern void bta_gatts_close(tBTA_GATTS_CB* p_cb, tBTA_GATTS_DATA* p_msg);
    177 
    178 extern bool bta_gatts_uuid_compare(tBT_UUID tar, tBT_UUID src);
    179 extern tBTA_GATTS_RCB* bta_gatts_find_app_rcb_by_app_if(
    180     tBTA_GATTS_IF server_if);
    181 extern uint8_t bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB* p_cb,
    182                                                     tBTA_GATTS_IF server_if);
    183 extern uint8_t bta_gatts_alloc_srvc_cb(tBTA_GATTS_CB* p_cb, uint8_t rcb_idx);
    184 extern tBTA_GATTS_SRVC_CB* bta_gatts_find_srvc_cb_by_srvc_id(
    185     tBTA_GATTS_CB* p_cb, uint16_t service_id);
    186 extern tBTA_GATTS_SRVC_CB* bta_gatts_find_srvc_cb_by_attr_id(
    187     tBTA_GATTS_CB* p_cb, uint16_t attr_id);
    188 
    189 #endif /* BTA_GATTS_INT_H */
    190