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_sys.h"
     29 #include "bta_gatt_api.h"
     30 #include "gatt_api.h"
     31 
     32 #include "gki.h"
     33 
     34 /*****************************************************************************
     35 **  Constants and data types
     36 *****************************************************************************/
     37 enum
     38 {
     39     BTA_GATTS_API_REG_EVT  = BTA_SYS_EVT_START(BTA_ID_GATTS),
     40     BTA_GATTS_INT_START_IF_EVT,
     41     BTA_GATTS_API_DEREG_EVT,
     42     BTA_GATTS_API_CREATE_SRVC_EVT,
     43     BTA_GATTS_API_INDICATION_EVT,
     44 
     45     BTA_GATTS_API_ADD_INCL_SRVC_EVT,
     46     BTA_GATTS_API_ADD_CHAR_EVT,
     47     BTA_GATTS_API_ADD_DESCR_EVT,
     48     BTA_GATTS_API_DEL_SRVC_EVT,
     49     BTA_GATTS_API_START_SRVC_EVT,
     50     BTA_GATTS_API_STOP_SRVC_EVT,
     51     BTA_GATTS_API_RSP_EVT,
     52     BTA_GATTS_API_OPEN_EVT,
     53     BTA_GATTS_API_CANCEL_OPEN_EVT,
     54     BTA_GATTS_API_CLOSE_EVT,
     55     BTA_GATTS_API_LISTEN_EVT,
     56     BTA_GATTS_API_DISABLE_EVT
     57 };
     58 typedef UINT16 tBTA_GATTS_INT_EVT;
     59 
     60 /* max number of application allowed on device */
     61 #define BTA_GATTS_MAX_APP_NUM   GATT_MAX_SR_PROFILES
     62 
     63 /* max number of services allowed in the device */
     64 #define BTA_GATTS_MAX_SRVC_NUM   GATT_MAX_SR_PROFILES
     65 
     66 /* internal strucutre for GATTC register API  */
     67 typedef struct
     68 {
     69     BT_HDR                  hdr;
     70     tBT_UUID                app_uuid;
     71     tBTA_GATTS_CBACK        *p_cback;
     72 }tBTA_GATTS_API_REG;
     73 
     74 typedef struct
     75 {
     76     BT_HDR                  hdr;
     77     tBTA_GATTS_IF           server_if;
     78 }tBTA_GATTS_INT_START_IF;
     79 
     80 typedef tBTA_GATTS_INT_START_IF tBTA_GATTS_API_DEREG;
     81 
     82 typedef struct
     83 {
     84     BT_HDR                  hdr;
     85     tBTA_GATTS_IF           server_if;
     86     tBT_UUID                service_uuid;
     87     UINT16                  num_handle;
     88     UINT8                   inst;
     89     BOOLEAN                 is_pri;
     90 
     91 } tBTA_GATTS_API_CREATE_SRVC;
     92 
     93 typedef struct
     94 {
     95     BT_HDR                  hdr;
     96     tBT_UUID                char_uuid;
     97     tBTA_GATT_PERM          perm;
     98     tBTA_GATT_CHAR_PROP     property;
     99 
    100 }tBTA_GATTS_API_ADD_CHAR;
    101 
    102 typedef struct
    103 {
    104     BT_HDR                  hdr;
    105     UINT16                  included_service_id;
    106 
    107 }tBTA_GATTS_API_ADD_INCL_SRVC;
    108 
    109 typedef struct
    110 {
    111     BT_HDR                      hdr;
    112     tBT_UUID                    descr_uuid;
    113     tBTA_GATT_PERM              perm;
    114 }tBTA_GATTS_API_ADD_DESCR;
    115 
    116 typedef struct
    117 {
    118     BT_HDR  hdr;
    119     UINT16  attr_id;
    120     UINT16  len;
    121     BOOLEAN need_confirm;
    122     UINT8   value[BTA_GATT_MAX_ATTR_LEN];
    123 }tBTA_GATTS_API_INDICATION;
    124 
    125 typedef struct
    126 {
    127     BT_HDR              hdr;
    128     UINT32              trans_id;
    129     tBTA_GATT_STATUS    status;
    130     tBTA_GATTS_RSP      *p_rsp;
    131 }tBTA_GATTS_API_RSP;
    132 
    133 typedef struct
    134 {
    135     BT_HDR                  hdr;
    136     tBTA_GATT_TRANSPORT     transport;
    137 }tBTA_GATTS_API_START;
    138 
    139 
    140 typedef struct
    141 {
    142     BT_HDR              hdr;
    143     BD_ADDR             remote_bda;
    144     tBTA_GATTS_IF       server_if;
    145     BOOLEAN             is_direct;
    146 }tBTA_GATTS_API_OPEN;
    147 
    148 typedef tBTA_GATTS_API_OPEN tBTA_GATTS_API_CANCEL_OPEN;
    149 
    150 typedef struct
    151 {
    152     BT_HDR                  hdr;
    153     BD_ADDR_PTR             remote_bda;
    154     tBTA_GATTS_IF           server_if;
    155     BOOLEAN                 start;
    156 } tBTA_GATTS_API_LISTEN;
    157 
    158 typedef union
    159 {
    160     BT_HDR                          hdr;
    161     tBTA_GATTS_API_REG              api_reg;
    162     tBTA_GATTS_API_DEREG            api_dereg;
    163     tBTA_GATTS_API_CREATE_SRVC      api_create_svc;
    164     tBTA_GATTS_API_ADD_INCL_SRVC    api_add_incl_srvc;
    165     tBTA_GATTS_API_ADD_CHAR         api_add_char;
    166     tBTA_GATTS_API_ADD_DESCR        api_add_char_descr;
    167     tBTA_GATTS_API_START            api_start;
    168     tBTA_GATTS_API_INDICATION       api_indicate;
    169     tBTA_GATTS_API_RSP              api_rsp;
    170     tBTA_GATTS_API_OPEN             api_open;
    171     tBTA_GATTS_API_CANCEL_OPEN      api_cancel_open;
    172 
    173     tBTA_GATTS_INT_START_IF         int_start_if;
    174     /* if peripheral role is supported */
    175     tBTA_GATTS_API_LISTEN           api_listen;
    176 } tBTA_GATTS_DATA;
    177 
    178 /* application registration control block */
    179 typedef struct
    180 {
    181     BOOLEAN             in_use;
    182     tBT_UUID            app_uuid;
    183     tBTA_GATTS_CBACK    *p_cback;
    184     tBTA_GATTS_IF        gatt_if;
    185 }tBTA_GATTS_RCB;
    186 
    187 /* service registration control block */
    188 typedef struct
    189 {
    190     tBT_UUID    service_uuid;   /* service UUID */
    191     UINT16      service_id;     /* service handle */
    192     UINT8       inst_num;       /* instance ID */
    193     UINT8       rcb_idx;
    194     UINT8       idx;            /* self index of serviec CB */
    195     BOOLEAN     in_use;
    196 
    197 }tBTA_GATTS_SRVC_CB;
    198 
    199 
    200 /* GATT server control block */
    201 typedef struct
    202 {
    203     BOOLEAN             enabled;
    204     tBTA_GATTS_RCB      rcb[BTA_GATTS_MAX_APP_NUM];
    205     tBTA_GATTS_SRVC_CB  srvc_cb[BTA_GATTS_MAX_SRVC_NUM];
    206 }tBTA_GATTS_CB;
    207 
    208 
    209 
    210 /*****************************************************************************
    211 **  Global data
    212 *****************************************************************************/
    213 
    214 /* GATTC control block */
    215 #if BTA_DYNAMIC_MEMORY == FALSE
    216 extern tBTA_GATTS_CB  bta_gatts_cb;
    217 #else
    218 extern tBTA_GATTS_CB *bta_gatts_cb_ptr;
    219     #define bta_gatts_cb (*bta_gatts_cb_ptr)
    220 #endif
    221 
    222 /*****************************************************************************
    223 **  Function prototypes
    224 *****************************************************************************/
    225 extern BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg);
    226 
    227 extern void bta_gatts_api_disable(tBTA_GATTS_CB *p_cb);
    228 extern void bta_gatts_api_enable(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_data);
    229 extern void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
    230 extern void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
    231 extern void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
    232 extern void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
    233 extern void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
    234 extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
    235 extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
    236 extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
    237 extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
    238 extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
    239 
    240 extern void bta_gatts_send_rsp(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
    241 extern void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
    242 
    243 
    244 extern void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
    245 extern void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
    246 extern void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
    247 extern void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
    248 
    249 extern BOOLEAN bta_gatts_uuid_compare(tBT_UUID tar, tBT_UUID src);
    250 extern tBTA_GATTS_RCB *bta_gatts_find_app_rcb_by_app_if(tBTA_GATTS_IF server_if);
    251 extern UINT8 bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_IF server_if);
    252 extern UINT8 bta_gatts_alloc_srvc_cb(tBTA_GATTS_CB *p_cb, UINT8 rcb_idx);
    253 extern tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT16 service_id);
    254 extern tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT16 attr_id);
    255 
    256 
    257 #endif /* BTA_GATTS_INT_H */
    258 
    259