예제 #1
0
/*******************************************************************************
**
** Function         gatt_cl_send_next_cmd_inq
**
** Description      Find next command in queue and sent to server
**
** Returns          TRUE if command sent, otherwise FALSE.
**
*******************************************************************************/
BOOLEAN gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb)
{
    tGATT_CMD_Q  *p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
    BOOLEAN     sent = FALSE;

    while (!sent &&
           p_tcb->pending_cl_req != p_tcb->next_slot_inq &&
           p_cmd->to_send && p_cmd->p_cmd != NULL)
    {
        sent = attp_send_msg_to_L2CAP(p_tcb, p_cmd->p_cmd);

        if (sent)
        {
            p_cmd->to_send = FALSE;
            p_cmd->p_cmd = NULL;

            gatt_start_rsp_timer (p_tcb);
        }
        else
        {
            GATT_TRACE_ERROR0("gatt_cl_send_next_cmd_inq: L2CAP sent error");

            memset(p_cmd, 0, sizeof(tGATT_CMD_Q));
            p_tcb->pending_cl_req ++;
            p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
        }
    }
    return sent;
}
/*******************************************************************************
**
** Function         gatt_cl_send_next_cmd_inq
**
** Description      Find next command in queue and sent to server
**
** Returns          TRUE if command sent, otherwise FALSE.
**
*******************************************************************************/
BOOLEAN gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb)
{
    tGATT_CMD_Q  *p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
    BOOLEAN     sent = FALSE;
    UINT8       rsp_code;
    tGATT_CLCB   *p_clcb = NULL;

    while (!sent &&
           p_tcb->pending_cl_req != p_tcb->next_slot_inq &&
           p_cmd->to_send && p_cmd->p_cmd != NULL)
    {
        sent = attp_send_msg_to_L2CAP(p_tcb, p_cmd->p_cmd);

        if (sent)
        {
            p_cmd->to_send = FALSE;
            p_cmd->p_cmd = NULL;

            /* dequeue the request if is write command or sign write */
            if (p_cmd->op_code != GATT_CMD_WRITE && p_cmd->op_code != GATT_SIGN_CMD_WRITE)
            {
                gatt_start_rsp_timer (p_tcb);
            }
            else
            {
                p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code);

                /* if no ack needed, keep sending */
                sent = FALSE;
                p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
                /* send command complete callback here */
                gatt_end_operation(p_clcb, GATT_SUCCESS, NULL);
            }
        }
        else
        {
            GATT_TRACE_ERROR0("gatt_cl_send_next_cmd_inq: L2CAP sent error");

            memset(p_cmd, 0, sizeof(tGATT_CMD_Q));
            p_tcb->pending_cl_req ++;
            p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
        }

    }
    return sent;
}