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

Commit a835780b authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

GATT Server refactoring (4/4)

Right now in order to add gatt service, we need to add it piece by
piece - each characteristic and descriptor separately. This causes lots
of concurrency errors in higher layers. Instead accept whole service
definition and start whole service at once.

Also, use handles to identify GATT server attributes. It's already done
on clinet side.

Bug: 27999121
Change-Id: I42c796809423d116fe6755ef8b1c40da270427a5
parent 46740010
Loading
Loading
Loading
Loading
+4 −205
Original line number Original line Diff line number Diff line
@@ -316,176 +316,7 @@ void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
        APPL_TRACE_ERROR("application not registered.");
        APPL_TRACE_ERROR("application not registered.");
    }
    }
}
}
/*******************************************************************************
**
** Function         bta_gatts_create_srvc
**
** Description      action function to create a service.
**
** Returns          none.
**
*******************************************************************************/
void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
{
    uint8_t               rcb_idx;
    tBTA_GATTS          cb_data;
    uint8_t               srvc_idx;
    uint16_t              service_id = 0;

    cb_data.create.status = BTA_GATT_ERROR;

    rcb_idx = bta_gatts_find_app_rcb_idx_by_app_if(p_cb, p_msg->api_create_svc.server_if);

    APPL_TRACE_ERROR("create service rcb_idx = %d", rcb_idx);

    if (rcb_idx != BTA_GATTS_INVALID_APP)
    {
        if ((srvc_idx = bta_gatts_alloc_srvc_cb(p_cb, rcb_idx)) != BTA_GATTS_INVALID_APP)
        {
            /* create the service now */
            service_id = GATTS_CreateService (p_cb->rcb[rcb_idx].gatt_if,
                                              &p_msg->api_create_svc.service_uuid,
                                              p_msg->api_create_svc.inst,
                                              p_msg->api_create_svc.num_handle,
                                              p_msg->api_create_svc.is_pri);


            if (service_id != 0)
            {
                memcpy(&p_cb->srvc_cb[srvc_idx].service_uuid,
                    &p_msg->api_create_svc.service_uuid, sizeof(tBT_UUID));
                p_cb->srvc_cb[srvc_idx].service_id   = service_id;
                p_cb->srvc_cb[srvc_idx].inst_num     = p_msg->api_create_svc.inst;
                p_cb->srvc_cb[srvc_idx].idx          = srvc_idx;

                cb_data.create.status      = BTA_GATT_OK;
                cb_data.create.service_id  = service_id;
                cb_data.create.is_primary  = p_msg->api_create_svc.is_pri;
                cb_data.create.server_if   = p_cb->rcb[rcb_idx].gatt_if;
            }
            else
            {
                cb_data.status  = BTA_GATT_ERROR;
                memset(&p_cb->srvc_cb[srvc_idx], 0, sizeof(tBTA_GATTS_SRVC_CB));
                APPL_TRACE_ERROR("service creation failed.");
            }
            memcpy(&cb_data.create.uuid, &p_msg->api_create_svc.service_uuid, sizeof(tBT_UUID));
            cb_data.create.svc_instance= p_msg->api_create_svc.inst;
        }
        if (p_cb->rcb[rcb_idx].p_cback)
            (* p_cb->rcb[rcb_idx].p_cback)(BTA_GATTS_CREATE_EVT, &cb_data);
    }
    else /* application not registered */
    {
        APPL_TRACE_ERROR("Application not registered");
    }
}
/*******************************************************************************
**
** Function         bta_gatts_add_include_srvc
**
** Description      action function to add an included service.
**
** Returns          none.
**
*******************************************************************************/
void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb,tBTA_GATTS_DATA * p_msg)
{
    tBTA_GATTS_RCB  *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
    uint16_t          attr_id = 0;
    tBTA_GATTS      cb_data;

    attr_id = GATTS_AddIncludeService(p_msg->api_add_incl_srvc.hdr.layer_specific,
                                      p_msg->api_add_incl_srvc.included_service_id);

    cb_data.add_result.server_if = p_rcb->gatt_if;
    cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;
    cb_data.add_result.attr_id = attr_id;

    if (attr_id)
    {
        cb_data.add_result.status = BTA_GATT_OK;
    }
    else
    {
        cb_data.add_result.status = BTA_GATT_ERROR;
    }

    if (p_rcb->p_cback)
        (*p_rcb->p_cback)(BTA_GATTS_ADD_INCL_SRVC_EVT, &cb_data);
}
/*******************************************************************************
**
** Function         bta_gatts_add_char
**
** Description      action function to add characteristic.
**
** Returns          none.
**
*******************************************************************************/
void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
{
    tBTA_GATTS_RCB  *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
    uint16_t          attr_id = 0;
    tBTA_GATTS      cb_data;

    attr_id = GATTS_AddCharacteristic(p_msg->api_add_char.hdr.layer_specific,
                                      &p_msg->api_add_char.char_uuid,
                                      p_msg->api_add_char.perm,
                                      p_msg->api_add_char.property);
    cb_data.add_result.server_if = p_rcb->gatt_if;
    cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;
    cb_data.add_result.attr_id = attr_id;
    memcpy(&cb_data.add_result.char_uuid, &p_msg->api_add_char.char_uuid, sizeof(tBT_UUID));

    if (attr_id)
    {
        cb_data.add_result.status = BTA_GATT_OK;
    }
    else
    {
        cb_data.add_result.status = BTA_GATT_ERROR;
    }

    if (p_rcb->p_cback)
        (*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_EVT, &cb_data);
}
/*******************************************************************************
**
** Function         bta_gatts_add_char_descr
**
** Description      action function to add characteristic descriptor.
**
** Returns          none.
**
*******************************************************************************/
void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
{
    tBTA_GATTS_RCB  *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
    uint16_t          attr_id = 0;
    tBTA_GATTS      cb_data;

    attr_id = GATTS_AddCharDescriptor(p_msg->api_add_char_descr.hdr.layer_specific,
                                       p_msg->api_add_char_descr.perm,
                                       &p_msg->api_add_char_descr.descr_uuid);

    cb_data.add_result.server_if = p_rcb->gatt_if;
    cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;
    cb_data.add_result.attr_id = attr_id;
    memcpy(&cb_data.add_result.char_uuid, &p_msg->api_add_char_descr.descr_uuid, sizeof(tBT_UUID));

    if (attr_id)
    {
        cb_data.add_result.status = BTA_GATT_OK;
    }
    else
    {
        cb_data.add_result.status = BTA_GATT_ERROR;
    }

    if (p_rcb->p_cback)
        (*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_DESCR_EVT, &cb_data);

}
/*******************************************************************************
/*******************************************************************************
**
**
** Function         bta_gatts_delete_service
** Function         bta_gatts_delete_service
@@ -501,11 +332,11 @@ void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p
    tBTA_GATTS      cb_data;
    tBTA_GATTS      cb_data;


    cb_data.srvc_oper.server_if = p_rcb->gatt_if;
    cb_data.srvc_oper.server_if = p_rcb->gatt_if;
    cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;
    // cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;


    if (GATTS_DeleteService(p_rcb->gatt_if,
    if (GATTS_DeleteService(p_rcb->gatt_if,
                            &p_srvc_cb->service_uuid,
                            &p_srvc_cb->service_uuid,
                            p_srvc_cb->inst_num))
                            p_srvc_cb->service_id))
    {
    {
        cb_data.srvc_oper.status = BTA_GATT_OK;
        cb_data.srvc_oper.status = BTA_GATT_OK;
        memset(p_srvc_cb, 0, sizeof(tBTA_GATTS_SRVC_CB));
        memset(p_srvc_cb, 0, sizeof(tBTA_GATTS_SRVC_CB));
@@ -519,39 +350,7 @@ void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p
        (*p_rcb->p_cback)(BTA_GATTS_DELELTE_EVT, &cb_data);
        (*p_rcb->p_cback)(BTA_GATTS_DELELTE_EVT, &cb_data);


}
}
/*******************************************************************************
**
** Function         bta_gatts_start_service
**
** Description      action function to start a service.
**
** Returns          none.
**
*******************************************************************************/
void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
{
    tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
    tBTA_GATTS      cb_data;

    cb_data.srvc_oper.server_if = p_rcb->gatt_if;
    cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;

    if (GATTS_StartService(p_rcb->gatt_if,
                           p_srvc_cb->service_id,
                           p_msg->api_start.transport) ==  GATT_SUCCESS)
    {
        APPL_TRACE_DEBUG("bta_gatts_start_service service_id= %d", p_srvc_cb->service_id);
        cb_data.srvc_oper.status = BTA_GATT_OK;
    }
    else
    {
        cb_data.srvc_oper.status = BTA_GATT_ERROR;
    }


    if (p_rcb->p_cback)
        (*p_rcb->p_cback)(BTA_GATTS_START_EVT, &cb_data);

}
/*******************************************************************************
/*******************************************************************************
**
**
** Function         bta_gatts_stop_service
** Function         bta_gatts_stop_service
@@ -850,8 +649,8 @@ static void bta_gatts_send_request_cback (uint16_t conn_id,
    {
    {
        p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if);
        p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if);


        APPL_TRACE_DEBUG ("bta_gatts_send_request_cback conn_id=%d trans_id=%d req_type=%d",
        APPL_TRACE_DEBUG("%s: conn_id=%d trans_id=%d req_type=%d",
                            conn_id, trans_id, req_type);
                         __func__, conn_id, trans_id, req_type);


        if (p_rcb && p_rcb->p_cback)
        if (p_rcb && p_rcb->p_cback)
        {
        {
+30 −132
Original line number Original line Diff line number Diff line
@@ -32,6 +32,8 @@
#include "bta_gatt_api.h"
#include "bta_gatt_api.h"
#include "bta_gatts_int.h"
#include "bta_gatts_int.h"


void btif_to_bta_uuid(tBT_UUID *p_dest, const bt_uuid_t *p_src);

/*****************************************************************************
/*****************************************************************************
**  Constants
**  Constants
*****************************************************************************/
*****************************************************************************/
@@ -123,127 +125,47 @@ void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if)


/*******************************************************************************
/*******************************************************************************
**
**
** Function         BTA_GATTS_CreateService
** Function         BTA_GATTS_AddService
**
**
** Description      Create a service. When service creation is done, a callback
** Description      Add the given |service| and all included elements to the
**                  event BTA_GATTS_CREATE_SRVC_EVT is called to report status
**                  GATT database. a |BTA_GATTS_ADD_SRVC_EVT| is triggered to
**                  and service ID to the profile. The service ID obtained in
**                  report the status and attribute handles.
**                  the callback function needs to be used when adding included
**                  service and characteristics/descriptors into the service.
**
**
** Parameters       app_id: Profile ID this service is belonged to.
** Parameters       server_if: server interface.
**                  p_service_uuid: service UUID.
**                  service: pointer vector describing service.
**                  inst: instance ID number of this service.
**                  num_handle: numble of handle requessted for this service.
**                  is_primary: is this service a primary one or not.
**
**
** Returns          void
** Returns          Returns |BTA_GATT_OK| on success or |BTA_GATT_ERROR| if the
**                  service cannot be added.
**
**
*******************************************************************************/
*******************************************************************************/
void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, uint8_t inst,
extern uint16_t BTA_GATTS_AddService(tBTA_GATTS_IF server_if, vector<btgatt_db_element_t> &service)
                             uint16_t num_handle, bool is_primary)
{
{
    tBTA_GATTS_API_CREATE_SRVC *p_buf =
    uint8_t rcb_idx = bta_gatts_find_app_rcb_idx_by_app_if(&bta_gatts_cb, server_if);
        (tBTA_GATTS_API_CREATE_SRVC *)osi_malloc(sizeof(tBTA_GATTS_API_CREATE_SRVC));


    p_buf->hdr.event = BTA_GATTS_API_CREATE_SRVC_EVT;
    APPL_TRACE_ERROR("%s: rcb_idx = %d", __func__, rcb_idx);
    p_buf->server_if = server_if;
    p_buf->inst = inst;
    memcpy(&p_buf->service_uuid, p_service_uuid, sizeof(tBT_UUID));
    p_buf->num_handle = num_handle;
    p_buf->is_pri = is_primary;


    bta_sys_sendmsg(p_buf);
    if (rcb_idx == BTA_GATTS_INVALID_APP)
}
        return BTA_GATT_ERROR;
/*******************************************************************************
**
** Function         BTA_GATTS_AddIncludeService
**
** Description      This function is called to add an included service. After included
**                  service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
**                  is reported the included service ID.
**
** Parameters       service_id: service ID to which this included service is to
**                              be added.
**                  included_service_id: the service ID to be included.
**
** Returns          void
**
*******************************************************************************/
void BTA_GATTS_AddIncludeService(uint16_t service_id, uint16_t included_service_id)
{
    tBTA_GATTS_API_ADD_INCL_SRVC *p_buf =
        (tBTA_GATTS_API_ADD_INCL_SRVC *)osi_malloc(sizeof(tBTA_GATTS_API_ADD_INCL_SRVC));

    p_buf->hdr.event = BTA_GATTS_API_ADD_INCL_SRVC_EVT;
    p_buf->hdr.layer_specific = service_id;
    p_buf->included_service_id = included_service_id;


    bta_sys_sendmsg(p_buf);
    uint8_t srvc_idx = bta_gatts_alloc_srvc_cb(&bta_gatts_cb, rcb_idx);
}
    if (srvc_idx == BTA_GATTS_INVALID_APP)
        return BTA_GATT_ERROR;


/*******************************************************************************
    uint16_t status = GATTS_AddService(server_if, service.data(), service.size());
**
** Function         BTA_GATTS_AddCharacteristic
**
** Description      This function is called to add a characteristic into a service.
**
** Parameters       service_id: service ID to which this included service is to
**                              be added.
**                  p_char_uuid : Characteristic UUID.
**                  perm      : Characteristic value declaration attribute permission.
**                  property  : Characteristic Properties
**
** Returns          None
**
*******************************************************************************/
void BTA_GATTS_AddCharacteristic (uint16_t service_id,  tBT_UUID  *p_char_uuid,
                                  tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property)
{
    tBTA_GATTS_API_ADD_CHAR *p_buf =
        (tBTA_GATTS_API_ADD_CHAR *)osi_calloc(sizeof(tBTA_GATTS_API_ADD_CHAR));


    p_buf->hdr.event = BTA_GATTS_API_ADD_CHAR_EVT;
    if (status == GATT_SERVICE_STARTED) {
    p_buf->hdr.layer_specific = service_id;
        btif_to_bta_uuid(&bta_gatts_cb.srvc_cb[srvc_idx].service_uuid, &service[0].uuid);
    p_buf->perm = perm;
    p_buf->property = property;


    if (p_char_uuid)
        // service_id is equal to service start handle
        memcpy(&p_buf->char_uuid, p_char_uuid, sizeof(tBT_UUID));
        bta_gatts_cb.srvc_cb[srvc_idx].service_id   = service[0].attribute_handle;
        bta_gatts_cb.srvc_cb[srvc_idx].idx          = srvc_idx;


    bta_sys_sendmsg(p_buf);
        return BTA_GATT_OK;
    }else {
        memset(&bta_gatts_cb.srvc_cb[srvc_idx], 0, sizeof(tBTA_GATTS_SRVC_CB));
        APPL_TRACE_ERROR("%s: service creation failed.", __func__);
        return BTA_GATT_ERROR;
    }
    }

/*******************************************************************************
**
** Function         BTA_GATTS_AddCharDescriptor
**
** Description      This function is called to add characteristic descriptor. When
**                  it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
**                  to report the status and an ID number for this descriptor.
**
** Parameters       service_id: service ID to which this charatceristic descriptor is to
**                              be added.
**                  perm: descriptor access permission.
**                  p_descr_uuid: descriptor UUID.
**
** Returns          returns status.
**
*******************************************************************************/
void BTA_GATTS_AddCharDescriptor (uint16_t service_id,
                                  tBTA_GATT_PERM perm,
                                  tBT_UUID  * p_descr_uuid)
{
    tBTA_GATTS_API_ADD_DESCR *p_buf =
        (tBTA_GATTS_API_ADD_DESCR *)osi_calloc(sizeof(tBTA_GATTS_API_ADD_DESCR));

    p_buf->hdr.event = BTA_GATTS_API_ADD_DESCR_EVT;
    p_buf->hdr.layer_specific = service_id;
    p_buf->perm = perm;
    if (p_descr_uuid)
        memcpy(&p_buf->descr_uuid, p_descr_uuid, sizeof(tBT_UUID));

    bta_sys_sendmsg(p_buf);
}
}


/*******************************************************************************
/*******************************************************************************
@@ -268,30 +190,6 @@ void BTA_GATTS_DeleteService(uint16_t service_id)
    bta_sys_sendmsg(p_buf);
    bta_sys_sendmsg(p_buf);
}
}


/*******************************************************************************
**
** Function         BTA_GATTS_StartService
**
** Description      This function is called to start a service.
**
** Parameters       service_id: the service ID to be started.
**                  sup_transport: supported trasnport.
**
** Returns          None.
**
*******************************************************************************/
void BTA_GATTS_StartService(uint16_t service_id, tBTA_GATT_TRANSPORT sup_transport)
{
    tBTA_GATTS_API_START *p_buf =
        (tBTA_GATTS_API_START *)osi_malloc(sizeof(tBTA_GATTS_API_START));

    p_buf->hdr.event = BTA_GATTS_API_START_SRVC_EVT;
    p_buf->hdr.layer_specific = service_id;
    p_buf->transport = sup_transport;

    bta_sys_sendmsg(p_buf);
}

/*******************************************************************************
/*******************************************************************************
**
**
** Function         BTA_GATTS_StopService
** Function         BTA_GATTS_StopService
+5 −47
Original line number Original line Diff line number Diff line
@@ -39,14 +39,9 @@ enum
    BTA_GATTS_API_REG_EVT  = BTA_SYS_EVT_START(BTA_ID_GATTS),
    BTA_GATTS_API_REG_EVT  = BTA_SYS_EVT_START(BTA_ID_GATTS),
    BTA_GATTS_INT_START_IF_EVT,
    BTA_GATTS_INT_START_IF_EVT,
    BTA_GATTS_API_DEREG_EVT,
    BTA_GATTS_API_DEREG_EVT,
    BTA_GATTS_API_CREATE_SRVC_EVT,
    BTA_GATTS_API_INDICATION_EVT,
    BTA_GATTS_API_INDICATION_EVT,


    BTA_GATTS_API_ADD_INCL_SRVC_EVT,
    BTA_GATTS_API_ADD_CHAR_EVT,
    BTA_GATTS_API_ADD_DESCR_EVT,
    BTA_GATTS_API_DEL_SRVC_EVT,
    BTA_GATTS_API_DEL_SRVC_EVT,
    BTA_GATTS_API_START_SRVC_EVT,
    BTA_GATTS_API_STOP_SRVC_EVT,
    BTA_GATTS_API_STOP_SRVC_EVT,
    BTA_GATTS_API_RSP_EVT,
    BTA_GATTS_API_RSP_EVT,
    BTA_GATTS_API_OPEN_EVT,
    BTA_GATTS_API_OPEN_EVT,
@@ -83,35 +78,9 @@ typedef struct
{
{
    BT_HDR                  hdr;
    BT_HDR                  hdr;
    tBTA_GATTS_IF           server_if;
    tBTA_GATTS_IF           server_if;
    tBT_UUID                service_uuid;
    btgatt_db_element_t    *service;
    uint16_t                  num_handle;
    UINT16                  count;
    uint8_t                   inst;
} tBTA_GATTS_API_ADD_SERVICE;
    bool                 is_pri;

} tBTA_GATTS_API_CREATE_SRVC;

typedef struct
{
    BT_HDR                  hdr;
    tBT_UUID                char_uuid;
    tBTA_GATT_PERM          perm;
    tBTA_GATT_CHAR_PROP     property;

}tBTA_GATTS_API_ADD_CHAR;

typedef struct
{
    BT_HDR                  hdr;
    uint16_t                  included_service_id;

}tBTA_GATTS_API_ADD_INCL_SRVC;

typedef struct
{
    BT_HDR                      hdr;
    tBT_UUID                    descr_uuid;
    tBTA_GATT_PERM              perm;
}tBTA_GATTS_API_ADD_DESCR;


typedef struct
typedef struct
{
{
@@ -162,11 +131,7 @@ typedef union
    BT_HDR                          hdr;
    BT_HDR                          hdr;
    tBTA_GATTS_API_REG              api_reg;
    tBTA_GATTS_API_REG              api_reg;
    tBTA_GATTS_API_DEREG            api_dereg;
    tBTA_GATTS_API_DEREG            api_dereg;
    tBTA_GATTS_API_CREATE_SRVC      api_create_svc;
    tBTA_GATTS_API_ADD_SERVICE      api_add_service;
    tBTA_GATTS_API_ADD_INCL_SRVC    api_add_incl_srvc;
    tBTA_GATTS_API_ADD_CHAR         api_add_char;
    tBTA_GATTS_API_ADD_DESCR        api_add_char_descr;
    tBTA_GATTS_API_START            api_start;
    tBTA_GATTS_API_INDICATION       api_indicate;
    tBTA_GATTS_API_INDICATION       api_indicate;
    tBTA_GATTS_API_RSP              api_rsp;
    tBTA_GATTS_API_RSP              api_rsp;
    tBTA_GATTS_API_OPEN             api_open;
    tBTA_GATTS_API_OPEN             api_open;
@@ -190,12 +155,10 @@ typedef struct
typedef struct
typedef struct
{
{
    tBT_UUID    service_uuid;   /* service UUID */
    tBT_UUID    service_uuid;   /* service UUID */
    uint16_t      service_id;     /* service handle */
    uint16_t      service_id;     /* service start handle */
    uint8_t       inst_num;       /* instance ID */
    uint8_t       rcb_idx;
    uint8_t       rcb_idx;
    uint8_t       idx;            /* self index of serviec CB */
    uint8_t       idx;            /* self index of serviec CB */
    bool     in_use;
    bool     in_use;

}tBTA_GATTS_SRVC_CB;
}tBTA_GATTS_SRVC_CB;




@@ -226,12 +189,7 @@ extern void bta_gatts_api_enable(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_data);
extern void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);


extern void bta_gatts_send_rsp(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_send_rsp(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
+19 −32
Original line number Original line Diff line number Diff line
@@ -31,20 +31,6 @@
#include "bta_gatts_int.h"
#include "bta_gatts_int.h"
#include "bt_common.h"
#include "bt_common.h"


/* type for service building action functions */
typedef void (*tBTA_GATTS_SRVC_ACT)(tBTA_GATTS_SRVC_CB *p_rcb, tBTA_GATTS_DATA *p_data);

/* service building action function list */
const tBTA_GATTS_SRVC_ACT bta_gatts_srvc_build_act[] =
{
    bta_gatts_add_include_srvc,
    bta_gatts_add_char,
    bta_gatts_add_char_descr,
    bta_gatts_delete_service,
    bta_gatts_start_service,
    bta_gatts_stop_service,
};

/* GATTS control block */
/* GATTS control block */
tBTA_GATTS_CB  bta_gatts_cb;
tBTA_GATTS_CB  bta_gatts_cb;


@@ -61,7 +47,6 @@ tBTA_GATTS_CB bta_gatts_cb;
bool bta_gatts_hdl_event(BT_HDR *p_msg)
bool bta_gatts_hdl_event(BT_HDR *p_msg)
{
{
    tBTA_GATTS_CB *p_cb = &bta_gatts_cb;
    tBTA_GATTS_CB *p_cb = &bta_gatts_cb;
    tBTA_GATTS_SRVC_CB *p_srvc_cb = NULL;


    switch (p_msg->event)
    switch (p_msg->event)
    {
    {
@@ -81,10 +66,6 @@ bool bta_gatts_hdl_event(BT_HDR *p_msg)
            bta_gatts_deregister(p_cb, (tBTA_GATTS_DATA *) p_msg);
            bta_gatts_deregister(p_cb, (tBTA_GATTS_DATA *) p_msg);
            break;
            break;


        case BTA_GATTS_API_CREATE_SRVC_EVT:
            bta_gatts_create_srvc(p_cb, (tBTA_GATTS_DATA *) p_msg);
            break;

        case BTA_GATTS_API_INDICATION_EVT:
        case BTA_GATTS_API_INDICATION_EVT:
            bta_gatts_indicate_handle(p_cb,(tBTA_GATTS_DATA *) p_msg);
            bta_gatts_indicate_handle(p_cb,(tBTA_GATTS_DATA *) p_msg);
            break;
            break;
@@ -110,25 +91,31 @@ bool bta_gatts_hdl_event(BT_HDR *p_msg)
            break;
            break;




        case BTA_GATTS_API_ADD_INCL_SRVC_EVT:
        case BTA_GATTS_API_ADD_CHAR_EVT:
        case BTA_GATTS_API_ADD_DESCR_EVT:
        case BTA_GATTS_API_DEL_SRVC_EVT:
        case BTA_GATTS_API_DEL_SRVC_EVT:
        case BTA_GATTS_API_START_SRVC_EVT:
        {
        case BTA_GATTS_API_STOP_SRVC_EVT:
            tBTA_GATTS_SRVC_CB *p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,

                                ((tBTA_GATTS_DATA *)p_msg)->api_add_service.hdr.layer_specific);
            p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,
                                ((tBTA_GATTS_DATA *)p_msg)->api_add_incl_srvc.hdr.layer_specific);


            if (p_srvc_cb != NULL)
            if (p_srvc_cb != NULL)
            {
                bta_gatts_delete_service(p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
                bta_gatts_srvc_build_act[p_msg->event - BTA_GATTS_API_ADD_INCL_SRVC_EVT](p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
            }
            else
            else
            {
                APPL_TRACE_ERROR("%s: can't delete service - no srvc_cb found", __func__);
                APPL_TRACE_ERROR("service not created");

            break;
        }
        }

        case BTA_GATTS_API_STOP_SRVC_EVT:
        {
            tBTA_GATTS_SRVC_CB *p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,
                                ((tBTA_GATTS_DATA *)p_msg)->api_add_service.hdr.layer_specific);

            if (p_srvc_cb != NULL)
                bta_gatts_stop_service(p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
            else
                APPL_TRACE_ERROR("%s: can't stop service - no srvc_cb found", __func__);

            break;
            break;
        }


        default:
        default:
            break;
            break;
+17 −107

File changed.

Preview size limit exceeded, changes collapsed.

Loading