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

Commit 88c670be authored by Zhihai Xu's avatar Zhihai Xu Committed by Android (Google) Code Review
Browse files

Merge "LE: Add API to configure MTU for a given connection (2/4)" into klp-modular-dev

parents 0d330658 fd6d6f49
Loading
Loading
Loading
Loading
+79 −11
Original line number Diff line number Diff line
@@ -69,7 +69,8 @@ static UINT16 bta_gattc_opcode_to_int_evt[] =
{
    BTA_GATTC_API_READ_EVT,
    BTA_GATTC_API_WRITE_EVT,
    BTA_GATTC_API_EXEC_EVT
    BTA_GATTC_API_EXEC_EVT,
    BTA_GATTC_API_CFG_MTU_EVT
};

#if (BT_TRACE_VERBOSE == TRUE)
@@ -349,7 +350,8 @@ void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
                bta_gattc_send_open_cback(p_clreg,
                                          BTA_GATT_NO_RESOURCES,
                                          p_msg->api_conn.remote_bda,
                                          BTA_GATT_INVALID_CONN_ID);
                                          BTA_GATT_INVALID_CONN_ID,
                                          0);
            }
        }
        else
@@ -473,7 +475,8 @@ void bta_gattc_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    bta_gattc_send_open_cback(p_clcb->p_rcb,
                              BTA_GATT_OK,
                              p_clcb->bda,
                              p_clcb->bta_conn_id);
                              p_clcb->bta_conn_id,
                              0);
}
/*******************************************************************************
**
@@ -491,7 +494,8 @@ void bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    bta_gattc_send_open_cback(p_clcb->p_rcb,
                              BTA_GATT_ERROR,
                              p_clcb->bda,
                              p_clcb->bta_conn_id);
                              p_clcb->bta_conn_id,
                              0);

    /* open failure, remove clcb */
    bta_gattc_clcb_dealloc(p_clcb);
@@ -579,7 +583,7 @@ void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg
    /* open failure, report OPEN_EVT */
    if (status != BTA_GATT_OK)
    {
        bta_gattc_send_open_cback(p_clreg, status, p_data->remote_bda, BTA_GATT_INVALID_CONN_ID);
        bta_gattc_send_open_cback(p_clreg, status, p_data->remote_bda, BTA_GATT_INVALID_CONN_ID, 0);
    }
}
/*******************************************************************************
@@ -687,6 +691,10 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    }

        p_clcb->p_srcb->connected = TRUE;

        if (p_clcb->p_srcb->mtu == 0)
            p_clcb->p_srcb->mtu = GATT_DEF_BLE_MTU_SIZE;

        /* start database cache if needed */
        if (p_clcb->p_srcb->p_srvc_cache == NULL ||
            p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE)
@@ -719,7 +727,8 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
            bta_gattc_send_open_cback(p_clcb->p_rcb,
                                      BTA_GATT_OK,
                                      p_clcb->bda,
                                      p_clcb->bta_conn_id);
                                      p_clcb->bta_conn_id,
                                      p_clcb->p_srcb->mtu);
        }
    }
/*******************************************************************************
@@ -871,6 +880,38 @@ void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data
    p_clcb->status      = BTA_GATT_CANCEL;
    p_clcb->auto_update = BTA_GATTC_DISC_WAITING;
}

/*******************************************************************************
**
** Function         bta_gattc_cfg_mtu
**
** Description      Configure MTU size on the GATT connection.
**
** Returns          None.
**
*******************************************************************************/
void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
{
    tBTA_GATTC_OP_CMPL  op_cmpl;
    tBTA_GATT_STATUS    status;

    if (bta_gattc_enqueue(p_clcb, p_data))
    {
        status = GATTC_ConfigureMTU (p_clcb->bta_conn_id, p_data->api_mtu.mtu);

        /* if failed, return callback here */
        if (status != GATT_SUCCESS && status != GATT_CMD_STARTED)
        {
            memset(&op_cmpl, 0, sizeof(tBTA_GATTC_OP_CMPL));

            op_cmpl.status  = status;
            op_cmpl.op_code = GATTC_OPTYPE_CONFIG;
            op_cmpl.p_cmpl  = NULL;

            bta_gattc_sm_execute(p_clcb, BTA_GATTC_OP_CMPL_EVT, (tBTA_GATTC_DATA *)&op_cmpl);
        }
    }
}
/*******************************************************************************
**
** Function         bta_gattc_start_discover
@@ -1345,6 +1386,35 @@ void bta_gattc_exec_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)

    ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_EXEC_EVT,  &cb_data);

}

/*******************************************************************************
**
** Function         bta_gattc_cfg_mtu_cmpl
**
** Description      configure MTU operation complete
**
** Returns          None.
**
*******************************************************************************/
void bta_gattc_cfg_mtu_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
{
    tBTA_GATTC          cb_data;

    utl_freebuf((void **)&p_clcb->p_q_cmd);


    if (p_data->p_cmpl  &&  p_data->status == BTA_GATT_OK)
        p_clcb->p_srcb->mtu  = p_data->p_cmpl->mtu;

    /* configure MTU complete, callback */
    p_clcb->status          = p_data->status;
    cb_data.cfg_mtu.conn_id = p_clcb->bta_conn_id;
    cb_data.cfg_mtu.status  = p_data->status;
    cb_data.cfg_mtu.mtu     = p_clcb->p_srcb->mtu;

    (*p_clcb->p_rcb->p_cback) (BTA_GATTC_CFG_MTU_EVT,  &cb_data);

}
/*******************************************************************************
**
@@ -1403,11 +1473,9 @@ void bta_gattc_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)

        else if (op == GATTC_OPTYPE_EXE_WRITE)
            bta_gattc_exec_cmpl(p_clcb, &p_data->op_cmpl);
        /*
        else if (op == GATTC_OPTYPE_CONFIG) // API to be added
        {
        }
       */

        else if (op == GATTC_OPTYPE_CONFIG)
            bta_gattc_cfg_mtu_cmpl(p_clcb, &p_data->op_cmpl);
    }
}
/*******************************************************************************
+28 −0
Original line number Diff line number Diff line
@@ -224,6 +224,34 @@ void BTA_GATTC_Close(UINT16 conn_id)
}
/*******************************************************************************
**
** Function         BTA_GATTC_ConfigureMTU
**
** Description      Configure the MTU size in the GATT channel. This can be done
**                  only once per connection.
**
** Parameters       conn_id: connection ID.
**                  mtu: desired MTU size to use.
**
** Returns          void
**
*******************************************************************************/
void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
{
    tBTA_GATTC_API_CFG_MTU  *p_buf;

    if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) GKI_getbuf(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL)
    {
        p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
        p_buf->hdr.layer_specific = conn_id;

        p_buf->mtu = mtu;

        bta_sys_sendmsg(p_buf);
    }
    return;
}
/*******************************************************************************
**
** Function         BTA_GATTC_ServiceSearchRequest
**
** Description      This function is called to request a GATT service discovery
+12 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ enum
    BTA_GATTC_API_READ_EVT,
    BTA_GATTC_API_WRITE_EVT,
    BTA_GATTC_API_EXEC_EVT,
    BTA_GATTC_API_CFG_MTU_EVT,

    BTA_GATTC_API_CLOSE_EVT,

@@ -188,6 +189,13 @@ typedef struct
    BOOLEAN                 start;
} tBTA_GATTC_API_LISTEN;


typedef struct
{
    BT_HDR              hdr;
    UINT16              mtu;
}tBTA_GATTC_API_CFG_MTU;

typedef struct
{
    BT_HDR                  hdr;
@@ -217,6 +225,7 @@ typedef union
    tBTA_GATTC_API_CONFIRM      api_confirm;
    tBTA_GATTC_API_EXEC         api_exec;
    tBTA_GATTC_API_READ_MULTI   api_read_multi;
    tBTA_GATTC_API_CFG_MTU      api_mtu;
    tBTA_GATTC_OP_CMPL          op_cmpl;
    tBTA_GATTC_CI_EVT           ci_open;
    tBTA_GATTC_CI_EVT           ci_save;
@@ -327,6 +336,7 @@ typedef struct
    UINT8               srvc_hdl_chg;   /* service handle change indication pending */
    UINT16              attr_index;     /* cahce NV saving/loading attribute index */

    UINT16              mtu;
} tBTA_GATTC_SERV;

#ifndef BTA_GATTC_NOTIF_REG_MAX
@@ -481,8 +491,9 @@ extern void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA
extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg);
extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data);
extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
                                       BD_ADDR remote_bda, UINT16 conn_id);
                                       BD_ADDR remote_bda, UINT16 conn_id, UINT16 mtu);
extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
#if BLE_INCLUDED == TRUE
extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
+9 −1
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ enum
    BTA_GATTC_IGNORE_OP_CMPL,
    BTA_GATTC_DISC_CLOSE,
    BTA_GATTC_RESTART_DISCOVER,
    BTA_GATTC_CFG_MTU,

    BTA_GATTC_IGNORE
};
@@ -106,7 +107,8 @@ const tBTA_GATTC_ACTION bta_gattc_action[] =
    bta_gattc_cache_open,
    bta_gattc_ignore_op_cmpl,
    bta_gattc_disc_close,
    bta_gattc_restart_discover
    bta_gattc_restart_discover,
    bta_gattc_cfg_mtu
};


@@ -127,6 +129,7 @@ static const UINT8 bta_gattc_st_idle[][BTA_GATTC_NUM_COLS] =
/* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},

/* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CLOSE_FAIL,        BTA_GATTC_IDLE_ST},

@@ -161,6 +164,7 @@ static const UINT8 bta_gattc_st_w4_conn[][BTA_GATTC_NUM_COLS] =
/* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_IGNORE,             BTA_GATTC_W4_CONN_ST},

/* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CANCEL_OPEN,         BTA_GATTC_W4_CONN_ST},

@@ -194,6 +198,7 @@ static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] =
/* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_READ,               BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_WRITE,              BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_EXEC,               BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_CFG_MTU,            BTA_GATTC_CONN_ST},

/* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CLOSE,              BTA_GATTC_IDLE_ST},

@@ -228,6 +233,7 @@ static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] =
/* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},

/* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_DISC_CLOSE,         BTA_GATTC_DISCOVER_ST},

@@ -489,6 +495,8 @@ static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code)
            return "BTA_GATTC_API_LISTEN_EVT";
        case BTA_GATTC_API_DISABLE_EVT:
            return "BTA_GATTC_API_DISABLE_EVT";
        case BTA_GATTC_API_CFG_MTU_EVT:
            return "BTA_GATTC_API_CFG_MTU_EVT";
        default:
            return "unknown GATTC event code";
    }
+15 −1
Original line number Diff line number Diff line
@@ -294,6 +294,7 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb)
        {
            p_srcb->connected = FALSE;
            p_srcb->state = BTA_GATTC_SERV_IDLE;
            p_srcb->mtu = 0;
        }

        utl_freebuf((void **)&p_clcb->p_q_cmd);
@@ -557,6 +558,18 @@ BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
                }
                break;
            }
            case BTA_GATTC_API_CFG_MTU_EVT:
            {
                len = sizeof(tBTA_GATTC_API_CFG_MTU);
                p_clcb->p_q_cmd = (tBTA_GATTC_DATA *)GKI_getbuf(len);
                if (p_clcb->p_q_cmd == NULL)
                {
                    APPL_TRACE_ERROR0("allocate buffer failed for p_q_cmd");
                    return FALSE;
                }
                memcpy(p_clcb->p_q_cmd, p_data, len);
                break;
            }
            default:
                APPL_TRACE_ERROR1("queue unsupported command %d", p_data->hdr.event);
                return FALSE;
@@ -906,7 +919,7 @@ BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, U
**
*******************************************************************************/
void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
                                BD_ADDR remote_bda, UINT16 conn_id)
                                BD_ADDR remote_bda, UINT16 conn_id, UINT16 mtu)
{
    tBTA_GATTC      cb_data;

@@ -917,6 +930,7 @@ void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status
        cb_data.open.status = status;
        cb_data.open.client_if = p_clreg->client_if;
        cb_data.open.conn_id = conn_id;
        cb_data.open.mtu = mtu;
        bdcpy(cb_data.open.remote_bda, remote_bda);

        (*p_clreg->p_cback)(BTA_GATTC_OPEN_EVT, &cb_data);
Loading