Пример #1
0
/*******************************************************************************
**
** Function         hidh_l2cif_cong_ind
**
** Description      This function handles a congestion status event from L2CAP.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_cong_ind (UINT16 l2cap_cid, BOOLEAN congested)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;

    /* Find CCB based on CID */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
        p_hcon = &hh_cb.devices[dhandle].conn;

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP congestion status, unknown CID: 0x%x", l2cap_cid);
        return;
    }

    HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP congestion status, CID: 0x%x  Cong: %d", l2cap_cid, congested);

    if (congested)
        p_hcon->conn_flags |= HID_CONN_FLAGS_CONGESTED;
    else
    {
        p_hcon->conn_flags &= ~HID_CONN_FLAGS_CONGESTED;

    }
}
/*******************************************************************************
**
** Function         hidh_l2cif_disconnect_cfm
**
** Description      This function handles a disconnect confirm event from L2CAP.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_disconnect_cfm (UINT16 l2cap_cid, UINT16 result)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;

    /* Find CCB based on CID */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
        p_hcon = &hh_cb.devices[dhandle].conn;

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING1 ("HID-Host Rcvd L2CAP disc cfm, unknown CID: 0x%x", l2cap_cid);
        return;
    }

    HIDH_TRACE_EVENT1 ("HID-Host Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid);

    if (l2cap_cid == p_hcon->ctrl_cid)
        p_hcon->ctrl_cid = 0;
    else
        p_hcon->intr_cid = 0;

    if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0))
    {
        hh_cb.devices[dhandle].state = HID_DEV_NO_CONN;
        p_hcon->conn_state = HID_CONN_STATE_UNUSED;
        hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, p_hcon->disc_reason, NULL ) ;
    }
}
/*******************************************************************************
**
** Function         hidh_l2cif_config_ind
**
** Description      This function processes the L2CAP configuration indication
**                  event.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;
    tHID_HOST_DEV_CTB *p_dev;

    /* Find CCB based on CID */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
    {
        p_dev = &hh_cb.devices[dhandle];
        p_hcon = &hh_cb.devices[dhandle].conn;
    }

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING1 ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
        return;
    }

    HIDH_TRACE_EVENT1 ("HID-Host Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid);

    /* Remember the remote MTU size */
    if ((!p_cfg->mtu_present) || (p_cfg->mtu > HID_HOST_MTU))
        p_hcon->rem_mtu_size = HID_HOST_MTU;
    else
        p_hcon->rem_mtu_size = p_cfg->mtu;

    /* For now, always accept configuration from the other side */
    p_cfg->flush_to_present = FALSE;
    p_cfg->mtu_present      = FALSE;
    p_cfg->result           = L2CAP_CFG_OK;

    L2CA_ConfigRsp (l2cap_cid, p_cfg);

    if (l2cap_cid == p_hcon->ctrl_cid)
        p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_CTRL_CFG_DONE;
    else
        p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_INTR_CFG_DONE;

    /* If all configuration is complete, change state and tell management we are up */
    if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED)
     && (p_hcon->conn_state == HID_CONN_STATE_CONFIG))
    {
        p_hcon->conn_state = HID_CONN_STATE_CONNECTED;

        hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
        hh_cb.callback( dhandle,  hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
    }
}
/*******************************************************************************
**
** Function         hidh_l2cif_config_cfm
**
** Description      This function processes the L2CAP configuration confirmation
**                  event.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;
    UINT32  reason;

    HIDH_TRACE_EVENT2 ("HID-Host Rcvd cfg cfm, CID: 0x%x  Result: %d", l2cap_cid, p_cfg->result);

    /* Find CCB based on CID */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
        p_hcon = &hh_cb.devices[dhandle].conn;

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING1 ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
        return;
    }

    /* If configuration failed, disconnect the channel(s) */
    if (p_cfg->result != L2CAP_CFG_OK)
    {
        hidh_conn_disconnect (dhandle);
        reason = HID_L2CAP_CFG_FAIL | (UINT32) p_cfg->result ;
        hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
        return;
    }

    if (l2cap_cid == p_hcon->ctrl_cid)
        p_hcon->conn_flags |= HID_CONN_FLAGS_MY_CTRL_CFG_DONE;
    else
        p_hcon->conn_flags |= HID_CONN_FLAGS_MY_INTR_CFG_DONE;

    /* If all configuration is complete, change state and tell management we are up */
    if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED)
     && (p_hcon->conn_state == HID_CONN_STATE_CONFIG))
    {
        p_hcon->conn_state = HID_CONN_STATE_CONNECTED;

        hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
        hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
    }
}
Пример #5
0
/*******************************************************************************
**
** Function         hidh_l2cif_data_ind
**
** Description      This function is called when data is received from L2CAP.
**                  if we are the originator of the connection, we are the SDP
**                  client, and the received message is queued up for the client.
**
**                  If we are the destination of the connection, we are the SDP
**                  server, so the message is passed to the server processing
**                  function.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
{
    UINT8           *p_data = (UINT8 *)(p_msg + 1) + p_msg->offset;
    UINT8           ttype, param, rep_type, evt;
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;

    HIDH_TRACE_DEBUG ("HID-Host hidh_l2cif_data_ind [l2cap_cid=0x%04x]", l2cap_cid);

    /* Find CCB based on CID */
     if ((dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES)
        p_hcon = &hh_cb.devices[dhandle].conn;

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid);
        GKI_freebuf (p_msg);
        return;
    }


    ttype    = HID_GET_TRANS_FROM_HDR(*p_data);
    param    = HID_GET_PARAM_FROM_HDR(*p_data);
    rep_type = param & HID_PAR_REP_TYPE_MASK;
    p_data++;

    /* Get rid of the data type */
    p_msg->len--;
    p_msg->offset++;

    switch (ttype)
    {
    case HID_TRANS_HANDSHAKE:
        hh_cb.callback(dhandle,  hh_cb.devices[dhandle].addr, HID_HDEV_EVT_HANDSHAKE, param, NULL);
        GKI_freebuf (p_msg);
        break;

    case HID_TRANS_CONTROL:
        switch (param)
        {
        case HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG:
            hidh_conn_disconnect( dhandle ) ;
            /* Device is unplugging from us. Tell USB */
            hh_cb.callback(dhandle,  hh_cb.devices[dhandle].addr, HID_HDEV_EVT_VC_UNPLUG, 0, NULL);
            break;

        default:
            break;
        }
        GKI_freebuf (p_msg);
        break;


    case HID_TRANS_DATA:
        HIDH_TRACE_VERBOSE ("HID-Host hidh_l2cif_data_ind [l2cap_cid=0x%04x], ttype=%02x]", l2cap_cid, ttype);
        evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) ?
                    HID_HDEV_EVT_INTR_DATA : HID_HDEV_EVT_CTRL_DATA;
        hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, evt, rep_type, p_msg);
        break;

    case HID_TRANS_DATAC:
        evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) ?
                    HID_HDEV_EVT_INTR_DATC : HID_HDEV_EVT_CTRL_DATC;
        hh_cb.callback(dhandle,  hh_cb.devices[dhandle].addr, evt, rep_type, p_msg);
        break;

    default:
        GKI_freebuf (p_msg);
        break;
    }

}
Пример #6
0
/*******************************************************************************
**
** Function         hidh_l2cif_disconnect_ind
**
** Description      This function handles a disconnect event from L2CAP. If
**                  requested to, we ack the disconnect before dropping the CCB
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;
    UINT16 disc_res = HCI_SUCCESS;
    UINT16 hid_close_evt_reason;

    /* Find CCB based on CID */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
        p_hcon = &hh_cb.devices[dhandle].conn;

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
        return;
    }

    if (ack_needed)
        L2CA_DisconnectRsp (l2cap_cid);

    HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);

    p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING;

    if (l2cap_cid == p_hcon->ctrl_cid)
        p_hcon->ctrl_cid = 0;
    else
        p_hcon->intr_cid = 0;

    if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0))
    {
        hh_cb.devices[dhandle].state = HID_DEV_NO_CONN;
        p_hcon->conn_state = HID_CONN_STATE_UNUSED;

        if( !ack_needed )
            disc_res = btm_get_acl_disc_reason_code();

        HIDH_TRACE_EVENT ("HID-Host: acl disconnect reason %d", disc_res);

#if (HID_HOST_MAX_CONN_RETRY > 0)
        if( (disc_res == HCI_ERR_CONNECTION_TOUT || disc_res == HCI_ERR_UNSPECIFIED) &&
            (!(hh_cb.devices[dhandle].attr_mask & HID_RECONN_INIT)) &&
            (hh_cb.devices[dhandle].attr_mask & HID_NORMALLY_CONNECTABLE))
        {
            hh_cb.devices[dhandle].conn_tries = 0;
            hh_cb.devices[dhandle].conn.timer_entry.param = (UINT32) dhandle;
            HIDH_TRACE_EVENT ("HID-Host: starting timer for reconnection");
            btu_start_timer (&(hh_cb.devices[dhandle].conn.timer_entry), BTU_TTYPE_HID_HOST_REPAGE_TO, HID_HOST_REPAGE_WIN);
            hh_cb.callback( dhandle,  hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, disc_res, NULL);
        }
        else
#endif
        {
            /* Set reason code for HID_HDEV_EVT_CLOSE */
            hid_close_evt_reason = p_hcon->disc_reason;

            /* If we got baseband sent HCI_DISCONNECT_COMPLETE_EVT due to security failure, then set reason to HID_ERR_AUTH_FAILED */
            if ((disc_res == HCI_ERR_AUTH_FAILURE)                        ||
                (disc_res == HCI_ERR_KEY_MISSING)                         ||
                (disc_res == HCI_ERR_HOST_REJECT_SECURITY)                ||
                (disc_res == HCI_ERR_PAIRING_NOT_ALLOWED)                 ||
                (disc_res == HCI_ERR_UNIT_KEY_USED)                       ||
                (disc_res == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) ||
                (disc_res == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE)           ||
                (disc_res == HCI_ERR_REPEATED_ATTEMPTS))
            {
                hid_close_evt_reason = HID_ERR_AUTH_FAILED;
            }
            HIDH_TRACE_EVENT ("HID-Host: disconnect ind, reason = %d", hid_close_evt_reason);
            hh_cb.callback( dhandle,  hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, hid_close_evt_reason, NULL ) ;
        }
    }
}
Пример #7
0
/*******************************************************************************
**
** Function         hidh_l2cif_config_cfm
**
** Description      This function processes the L2CAP configuration confirmation
**                  event.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;
    UINT32  reason;

    HIDH_TRACE_EVENT ("HID-Host Rcvd cfg cfm, CID: 0x%x  Result: %d", l2cap_cid, p_cfg->result);

    /* Find CCB based on CID */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
        p_hcon = &hh_cb.devices[dhandle].conn;

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
        return;
    }

    /* If configuration failed, disconnect the channel(s) */
    if (p_cfg->result != L2CAP_CFG_OK)
    {
        hidh_conn_disconnect (dhandle);
        reason = HID_L2CAP_CFG_FAIL | (UINT32) p_cfg->result ;
        HIDH_TRACE_WARNING ("HID-Host: l2cap config ind failed, reason = %d", reason);
        hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
        return;
    }

    if (l2cap_cid == p_hcon->ctrl_cid)
    {
        p_hcon->conn_flags |= HID_CONN_FLAGS_MY_CTRL_CFG_DONE;
        if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) &&
           (p_hcon->conn_flags & HID_CONN_FLAGS_HIS_CTRL_CFG_DONE))
        {
            /* Connect interrupt channel */
            p_hcon->disc_reason = HID_L2CAP_CONN_FAIL;  /* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */
            if ((p_hcon->intr_cid = L2CA_ConnectReq (HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr)) == 0)
            {
                HIDH_TRACE_WARNING ("HID-Host INTR Originate failed");
                reason = HID_L2CAP_REQ_FAIL ;
                p_hcon->conn_state = HID_CONN_STATE_UNUSED;
                hidh_conn_disconnect (dhandle);
                HIDH_TRACE_WARNING ("HID-Host: l2cap config ind failed 2, reason = %d", reason);
                hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
                return;
            }
            else
            {
                /* Transition to the next appropriate state, waiting for connection confirm on interrupt channel. */
                p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
            }
        }
    }
    else
        p_hcon->conn_flags |= HID_CONN_FLAGS_MY_INTR_CFG_DONE;

    /* If all configuration is complete, change state and tell management we are up */
    if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED)
     && (p_hcon->conn_state == HID_CONN_STATE_CONFIG))
    {
        p_hcon->conn_state = HID_CONN_STATE_CONNECTED;
        /* Reset disconnect reason to success, as connection successful */
        p_hcon->disc_reason = HID_SUCCESS;

        hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
        hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
    }
}
Пример #8
0
/*******************************************************************************
**
** Function         hidh_l2cif_connect_cfm
**
** Description      This function handles the connect confirm events
**                  from L2CAP. This is the case when we are acting as a
**                  client and have sent a connect request.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;
    UINT32  reason;
    tHID_HOST_DEV_CTB *p_dev = NULL;

    /* Find CCB based on CID, and verify we are in a state to accept this message */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
    {
        p_dev = &hh_cb.devices[dhandle];
        p_hcon = &hh_cb.devices[dhandle].conn;
    }

    if ((p_hcon == NULL)
     || (!(p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG))
     || ((l2cap_cid == p_hcon->ctrl_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_CTRL))
     || ((l2cap_cid == p_hcon->intr_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR)
     && (p_hcon->conn_state != HID_CONN_STATE_DISCONNECTING)))
    {
        HIDH_TRACE_WARNING ("HID-Host Rcvd unexpected conn cnf, CID 0x%x ", l2cap_cid);
        return;
    }

    if (result != L2CAP_CONN_OK)
    {
        if (l2cap_cid == p_hcon->ctrl_cid)
            p_hcon->ctrl_cid = 0;
        else
            p_hcon->intr_cid = 0;

        hidh_conn_disconnect(dhandle);

#if (HID_HOST_MAX_CONN_RETRY > 0)
        if( (hh_cb.devices[dhandle].conn_tries <= HID_HOST_MAX_CONN_RETRY) &&
            (result == HCI_ERR_CONNECTION_TOUT || result == HCI_ERR_UNSPECIFIED ||
             result == HCI_ERR_PAGE_TIMEOUT) )
        {
            hidh_conn_retry(dhandle);
        }
        else
#endif
        {
            reason = HID_L2CAP_CONN_FAIL | (UINT32) result ;
            HIDH_TRACE_WARNING ("HID-Host: l2cap connect failed, reason = %d", reason);
            hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
        }
        return;
    }
    /* receive Control Channel connect confirmation */
    if (l2cap_cid == p_hcon->ctrl_cid)
    {
        /* check security requirement */
        p_hcon->conn_state = HID_CONN_STATE_SECURITY;
        p_hcon->disc_reason = HID_L2CAP_CONN_FAIL;  /* In case disconnection occurs before security is completed, then set CLOSE_EVT reason code to "connection failure" */

        if (!interop_addr_match(INTEROP_DISABLE_AUTH_FOR_HID_POINTING, (bt_bdaddr_t *)p_dev->addr))
        {
            btm_sec_mx_access_request (p_dev->addr, HID_PSM_CONTROL,
                TRUE, BTM_SEC_PROTO_HID,
                (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN,
                &hidh_sec_check_complete_orig, p_dev);
        }
        else
        {
            /* device is blacklisted, don't perform authentication */
             hidh_sec_check_complete_orig(p_dev->addr, BT_TRANSPORT_BR_EDR,
                p_dev, BTM_SUCCESS);
        }
    }
    else
    {
        p_hcon->conn_state = HID_CONN_STATE_CONFIG;
        /* Send a Configuration Request. */
        L2CA_ConfigReq (l2cap_cid, &hh_cb.l2cap_cfg);
        HIDH_TRACE_EVENT ("HID-Host got Interrupt conn cnf, sent cfg req, CID: 0x%x", l2cap_cid);
    }

    return;
}
Пример #9
0
/*******************************************************************************
**
** Function         hidh_l2cif_config_ind
**
** Description      This function processes the L2CAP configuration indication
**                  event.
**
** Returns          void
**
*******************************************************************************/
static void hidh_l2cif_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
{
    UINT8 dhandle;
    tHID_CONN    *p_hcon = NULL;
    UINT32  reason;

    /* Find CCB based on CID */
    if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
    {
        p_hcon = &hh_cb.devices[dhandle].conn;
    }

    if (p_hcon == NULL)
    {
        HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
        return;
    }

    HIDH_TRACE_EVENT ("HID-Host Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid);

    /* Remember the remote MTU size */
    if ((!p_cfg->mtu_present) || (p_cfg->mtu > HID_HOST_MTU))
        p_hcon->rem_mtu_size = HID_HOST_MTU;
    else
        p_hcon->rem_mtu_size = p_cfg->mtu;

    /* For now, always accept configuration from the other side */
    p_cfg->flush_to_present = FALSE;
    p_cfg->mtu_present      = FALSE;
    p_cfg->result           = L2CAP_CFG_OK;

    L2CA_ConfigRsp (l2cap_cid, p_cfg);

    if (l2cap_cid == p_hcon->ctrl_cid)
    {
        p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_CTRL_CFG_DONE;
        if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) &&
           (p_hcon->conn_flags & HID_CONN_FLAGS_MY_CTRL_CFG_DONE))
        {
            /* Connect interrupt channel */
            p_hcon->disc_reason = HID_L2CAP_CONN_FAIL;	/* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */
            if ((p_hcon->intr_cid = L2CA_ConnectReq (HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr)) == 0)
            {
                HIDH_TRACE_WARNING ("HID-Host INTR Originate failed");
                reason = HID_L2CAP_REQ_FAIL ;
                p_hcon->conn_state = HID_CONN_STATE_UNUSED;
                hidh_conn_disconnect (dhandle);
                hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
                return;
            }
            else
            {
                /* Transition to the next appropriate state, waiting for connection confirm on interrupt channel. */
                p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
            }
        }
    }
    else
        p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_INTR_CFG_DONE;

    /* If all configuration is complete, change state and tell management we are up */
    if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED)
     && (p_hcon->conn_state == HID_CONN_STATE_CONFIG))
    {
        p_hcon->conn_state = HID_CONN_STATE_CONNECTED;
        /* Reset disconnect reason to success, as connection successful */
        p_hcon->disc_reason = HID_SUCCESS;

        hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
        hh_cb.callback( dhandle,  hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
    }
}