Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19e7ef24 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Restructure GATTC

This patch changes how GATTC is structured. Up till now, it
contained tBTA_GATTC_CACHE and tBTA_GATTC_CACHE_ATTR. Those
structures were so ugly, someone hide them inside internal
header, to make sure noone would ever access them from outside
GATTC. They are now replaced with:
tBTA_GATTC_SERVICE,
tBTA_GATTC_CHARACTERISTIC,
tBTA_GATTC_DESCRIPTOR and
tBTA_GATTC_INCLUDED_SVC.

Those looks much better, and were made globally avaliable.
Thanks to way they're build, we no longer need set of access
methods, which were also very ugly:
BTA_GATTC_GetFirstChar
BTA_GATTC_GetNextChar
BTA_GATTC_GetFirstIncludedService
etc.

This patch breaks HID, DO NOT SUBMIT without HID refactor.

Bug: 27455533
Change-Id: Ic42cfff175e0cc1a0d8e1a1216e2b4b756cbf77d
parent 72d12524
Loading
Loading
Loading
Loading
+17 −136
Original line number Diff line number Diff line
@@ -259,168 +259,49 @@ void BTA_GATTC_ServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid)

/*******************************************************************************
**
** Function         BTA_GATTC_GetFirstChar
** Function         BTA_GATTC_GetServices
**
** Description      This function is called to find the first characteristic of the
**                  service on the given server.
** Description      This function is called to find the services on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  p_srvc_id: the service ID of which the characteristic is belonged to.
**                  p_char_uuid_cond: Characteristic UUID, if NULL find the first available
**                               characteristic.
**                  p_char_result: output parameter which will store the GATT
**                                  characteristic ID.
**                  p_property: output parameter to carry the characteristic property.
**
** Returns          returns status.
** Returns          returns list_t of tBTA_GATTC_SERVICE or NULL.
**
*******************************************************************************/
tBTA_GATT_STATUS  BTA_GATTC_GetFirstChar (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id,
                                          tBT_UUID *p_char_uuid_cond,
                                          tBTA_GATTC_CHAR_ID *p_char_result,
                                          tBTA_GATT_CHAR_PROP *p_property)
{
    tBTA_GATT_STATUS    status;

    if (!p_srvc_id || !p_char_result)
        return BTA_GATT_ILLEGAL_PARAMETER;

    if ((status = bta_gattc_query_cache(conn_id, BTA_GATTC_ATTR_TYPE_CHAR, p_srvc_id, NULL,
                                        p_char_uuid_cond, &p_char_result->char_id, (void *)p_property))
        == BTA_GATT_OK)
    {
        memcpy(&p_char_result->srvc_id, p_srvc_id, sizeof(tBTA_GATT_SRVC_ID));
const list_t* BTA_GATTC_GetServices(UINT16 conn_id) {
    return bta_gattc_get_services(conn_id);
}

    return status;

}
/*******************************************************************************
**
** Function         BTA_GATTC_GetNextChar
** Function         BTA_GATTC_GetCharacteristic
**
** Description      This function is called to find the next characteristic of the
**                  service on the given server.
** Description      This function is called to find the characteristic on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  p_start_char_id: start the characteristic search from the next record
**                           after the one identified by char_id.
**                  p_char_uuid_cond: Characteristic UUID, if NULL find the first available
**                               characteristic.
**                  p_char_result: output parameter which will store the GATT
**                                  characteristic ID.
**                  p_property: output parameter to carry the characteristic property.
**                  handle: characteristic handle
**
** Returns          returns status.
** Returns          returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
**
*******************************************************************************/
tBTA_GATT_STATUS  BTA_GATTC_GetNextChar (UINT16 conn_id,
                                         tBTA_GATTC_CHAR_ID *p_start_char_id,
                                         tBT_UUID           *p_char_uuid_cond,
                                         tBTA_GATTC_CHAR_ID *p_char_result,
                                         tBTA_GATT_CHAR_PROP    *p_property)
{
    tBTA_GATT_STATUS    status;

    if (!p_start_char_id || !p_char_result)
        return BTA_GATT_ILLEGAL_PARAMETER;

    if ((status = bta_gattc_query_cache(conn_id, BTA_GATTC_ATTR_TYPE_CHAR,
                                        &p_start_char_id->srvc_id,
                                        &p_start_char_id->char_id,
                                        p_char_uuid_cond,
                                        &p_char_result->char_id,
                                        (void *) p_property))
        == BTA_GATT_OK)
    {
        memcpy(&p_char_result->srvc_id, &p_start_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    }

    return status;
const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle) {
    return bta_gattc_get_characteristic(conn_id, handle);
}

/*******************************************************************************
**
** Function         BTA_GATTC_GetFirstCharDescr
** Function         BTA_GATTC_GetCharacteristic
**
** Description      This function is called to find the first characteristic descriptor of the
**                  characteristic on the given server.
** Description      This function is called to find the characteristic on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  p_char_id: the characteristic ID of which the descriptor is belonged to.
**                  p_descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available
**                               characteristic.
**                  p_descr_result: output parameter which will store the GATT
**                                  characteristic descriptor ID.
**                  handle: descriptor handle
**
** Returns          returns status.
** Returns          returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
**
*******************************************************************************/
tBTA_GATT_STATUS  BTA_GATTC_GetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
                                                tBT_UUID *p_descr_uuid_cond,
                                                tBTA_GATTC_CHAR_DESCR_ID *p_descr_result)
{
    tBTA_GATT_STATUS    status;

    if (!p_char_id || !p_descr_result)
        return BTA_GATT_ILLEGAL_PARAMETER;

    memset(p_descr_result, 0, sizeof(tBTA_GATTC_CHAR_DESCR_ID));

    if ((status = bta_gattc_query_cache(conn_id,
                                        BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
                                        &p_char_id->srvc_id,
                                        &p_char_id->char_id,
                                        p_descr_uuid_cond,
                                        &p_descr_result->char_id.char_id,
                                        NULL))
        == BTA_GATT_OK)
    {
        memcpy(&p_descr_result->descr_id, &p_descr_result->char_id.char_id, sizeof(tBTA_GATT_ID));
        memcpy(&p_descr_result->char_id, p_char_id, sizeof(tBTA_GATTC_CHAR_ID));
    }
    return status;

}

/*******************************************************************************
**
** Function         BTA_GATTC_GetFirstIncludedService
**
** Description      This function is called to find the first included service of the
**                  service on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  p_srvc_id: the service ID of which the characteristic is belonged to.
**                  p_uuid_cond: Characteristic UUID, if NULL find the first available
**                               characteristic.
**                  p_result: output parameter which will store the GATT ID
**                              of the included service found.
**
** Returns          returns status.
**
*******************************************************************************/
tBTA_GATT_STATUS  BTA_GATTC_GetFirstIncludedService(UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id,
                                                    tBT_UUID *p_uuid_cond, tBTA_GATTC_INCL_SVC_ID *p_result)
{
    tBTA_GATT_STATUS    status;

    if (!p_srvc_id || !p_result)
        return BTA_GATT_ILLEGAL_PARAMETER;

    if ((status = bta_gattc_query_cache(conn_id,
                                        BTA_GATTC_ATTR_TYPE_INCL_SRVC,
                                        p_srvc_id,
                                        NULL,
                                        p_uuid_cond,
                                        &p_result->incl_svc_id.id,
                                        (void *)&p_result->incl_svc_id.is_primary))
        == BTA_GATT_OK)
    {
        memcpy(&p_result->srvc_id, p_srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    }

    return status;
const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle) {
    return bta_gattc_get_descriptor(conn_id, handle);
}

/*******************************************************************************
+286 −290

File changed.

Preview size limit exceeded, changes collapsed.

+5 −27
Original line number Diff line number Diff line
@@ -237,28 +237,6 @@ typedef union


/* GATT server cache on the client */
typedef struct
{
    tBT_UUID                uuid;
    UINT16                  attr_handle;
    tBTA_GATT_CHAR_PROP     property; /* if characteristic, it is char property;
                                         if included service, flag primary,
                                         if descriptor, not used */
    tBTA_GATTC_ATTR_TYPE    attr_type;
// btla-specific ++
} __attribute__((packed)) tBTA_GATTC_CACHE_ATTR;
// btla-specific --

typedef struct
{
    tBTA_GATT_SRVC_ID       service_uuid;
    list_t                 *p_attr; /* list of tBTA_GATTC_CACHE_ATTR */
    UINT16                  s_handle;
    UINT16                  e_handle;
    list_node_t            *p_cur_char; /* node pointing to p_attr */
// btla-specific ++
} __attribute__((packed)) tBTA_GATTC_CACHE;
// btla-specific --

typedef struct
{
@@ -300,8 +278,7 @@ typedef struct

    UINT8               state;

    list_t              *p_srvc_cache;  /* list of tBTA_GATTC_CACHE */
    tBTA_GATTC_CACHE    *p_cur_srvc;
    list_t              *p_srvc_cache;  /* list of tBTA_GATTC_SERVICE */
    UINT8               update_count;   /* indication received */
    UINT8               num_clcb;       /* number of associated CLCB */

@@ -508,9 +485,10 @@ extern void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type
extern tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type);
extern tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type);
extern void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid);
extern tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id, UINT8 query_type, tBTA_GATT_SRVC_ID *p_srvc_id,
                                              tBTA_GATT_ID *p_start_rec,tBT_UUID *p_uuid_cond,
                                              tBTA_GATT_ID *p_output, void *p_param);
extern const list_t* bta_gattc_get_services(UINT16 conn_id);
extern const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle(UINT16 conn_id, UINT16 handle);
extern tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic(UINT16 conn_id, UINT16 handle);
extern tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(UINT16 conn_id, UINT16 handle);
extern void bta_gattc_get_gatt_db(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, btgatt_db_element_t **db, int *count);
extern tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb);
extern void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srcv, UINT16 num_attr, tBTA_GATTC_NV_ATTR *attr);
+76 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@

#include "bta_api.h"
#include "gatt_api.h"
#include "osi/include/list.h"

#ifndef     BTA_GATT_INCLUDED
#warning BTA_GATT_INCLUDED not defined
@@ -278,6 +279,7 @@ typedef struct
    UINT8       id;
    UINT8       prop;       /* used when attribute type is characteristic */
    BOOLEAN     is_primary; /* used when attribute type is service */
    UINT16      incl_srvc_handle; /* used when attribute type is included service */
}tBTA_GATTC_NV_ATTR;

/* callback data structure */
@@ -624,6 +626,39 @@ typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
/* Server callback function */
typedef void (tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event,  tBTA_GATTS *p_data);

typedef struct
{
    tBTA_GATT_SRVC_ID       service_uuid;
    UINT16                  s_handle;
    UINT16                  e_handle;
    list_t                 *characteristics; /* list of tBTA_GATTC_CHARACTERISTIC */
    list_t                 *included_svc; /* list of tBTA_GATTC_INCLUDED_SVC */
} __attribute__((packed)) tBTA_GATTC_SERVICE;

typedef struct
{
    tBT_UUID                uuid;
    UINT16                  handle;
    tBTA_GATT_CHAR_PROP     properties;
    tBTA_GATTC_SERVICE     *service; /* owning service*/
    list_t                 *descriptors; /* list of tBTA_GATTC_DESCRIPTOR */
} __attribute__((packed)) tBTA_GATTC_CHARACTERISTIC;

typedef struct
{
    tBT_UUID                    uuid;
    UINT16                      handle;
    tBTA_GATTC_CHARACTERISTIC  *characteristic; /* owning characteristic */
} __attribute__((packed)) tBTA_GATTC_DESCRIPTOR;

typedef struct
{
    tBT_UUID                uuid;
    UINT16                  handle;
    tBTA_GATTC_SERVICE     *owning_service; /* owning service*/
    tBTA_GATTC_SERVICE     *included_service;
} __attribute__((packed)) tBTA_GATTC_INCLUDED_SVC;

/*****************************************************************************
**  External Function Declarations
*****************************************************************************/
@@ -743,6 +778,47 @@ extern void BTA_GATTC_Close(UINT16 conn_id);
*******************************************************************************/
extern void BTA_GATTC_ServiceSearchRequest(UINT16 conn_id, tBT_UUID *p_srvc_uuid);

/*******************************************************************************
**
** Function         BTA_GATTC_GetServices
**
** Description      This function is called to find the services on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**
** Returns          returns list_t of tBTA_GATTC_SERVICE or NULL.
**
*******************************************************************************/
extern const list_t* BTA_GATTC_GetServices(UINT16 conn_id);

/*******************************************************************************
**
** Function         BTA_GATTC_GetCharacteristic
**
** Description      This function is called to find the characteristic on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  handle: characteristic handle
**
** Returns          returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
**
*******************************************************************************/
extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle);

/*******************************************************************************
**
** Function         BTA_GATTC_GetCharacteristic
**
** Description      This function is called to find the characteristic on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  handle: descriptor handle
**
** Returns          returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
**
*******************************************************************************/
extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle);

/*******************************************************************************
**
** Function         BTA_GATTC_GetFirstChar