/*******************************************************************************
**
** Function         nci_proc_ee_management_rsp
**
** Description      Process NCI responses in the NFCEE Management group
**
** Returns          void
**
*******************************************************************************/
void nci_proc_ee_management_rsp (BT_HDR *p_msg)
{
    UINT8   *p;
    UINT8   *pp, len, op_code;
    tNFC_RESPONSE_CBACK *p_cback = nfc_cb.p_resp_cback;
    tNFC_NFCEE_DISCOVER_REVT    nfcee_discover;
    tNFC_NFCEE_INFO_REVT        nfcee_info;
    tNFC_NFCEE_MODE_SET_REVT    mode_set;
    tNFC_RESPONSE   *p_evt = (tNFC_RESPONSE *) &nfcee_info;
    tNFC_RESPONSE_EVT event = NFC_NFCEE_INFO_REVT;
    UINT8   *p_old = nfc_cb.last_cmd;

    /* find the start of the NCI message and parse the NCI header */
    p   = (UINT8 *) (p_msg + 1) + p_msg->offset;
    pp  = p+1;
    NCI_MSG_PRS_HDR1 (pp, op_code);
    NFC_TRACE_DEBUG1 ("nci_proc_ee_management_rsp opcode:0x%x", op_code);
    len = *pp++;

    switch (op_code)
    {
    case NCI_MSG_NFCEE_DISCOVER:
        p_evt                       = (tNFC_RESPONSE *) &nfcee_discover;
        nfcee_discover.status       = *pp++;
        nfcee_discover.num_nfcee    = *pp++;

        if (nfcee_discover.status != NFC_STATUS_OK)
            nfcee_discover.num_nfcee    = 0;

        event                       = NFC_NFCEE_DISCOVER_REVT;
        break;

    case NCI_MSG_NFCEE_MODE_SET:
        p_evt                   = (tNFC_RESPONSE *) &mode_set;
        mode_set.status         = *pp;
        mode_set.nfcee_id       = 0;
        event                   = NFC_NFCEE_MODE_SET_REVT;
        mode_set.nfcee_id       = *p_old++;
        mode_set.mode           = *p_old++;
        break;

    default:
        p_cback = NULL;
        NFC_TRACE_ERROR1 ("unknown opcode:0x%x", op_code);
        break;
    }

    if (p_cback)
        (*p_cback) (event, p_evt);
}
/*******************************************************************************
**
** Function         nci_proc_core_rsp
**
** Description      Process NCI responses in the CORE group
**
** Returns          TRUE-caller of this function to free the GKI buffer p_msg
**
*******************************************************************************/
BOOLEAN nci_proc_core_rsp (BT_HDR *p_msg)
{
    UINT8   *p;
    UINT8   *pp, len, op_code;
    BOOLEAN free = TRUE;
    UINT8   *p_old = nfc_cb.last_cmd;

    /* find the start of the NCI message and parse the NCI header */
    p   = (UINT8 *) (p_msg + 1) + p_msg->offset;
    pp  = p+1;
    NCI_MSG_PRS_HDR1 (pp, op_code);
    NFC_TRACE_DEBUG1 ("nci_proc_core_rsp opcode:0x%x", op_code);
    len = *pp++;

    /* process the message based on the opcode and message type */
    switch (op_code)
    {
    case NCI_MSG_CORE_RESET:
        nfc_ncif_proc_reset_rsp (pp, FALSE);
        break;

    case NCI_MSG_CORE_INIT:
        nfc_ncif_proc_init_rsp (p_msg);
        free = FALSE;
        break;

    case NCI_MSG_CORE_GET_CONFIG:
        nfc_ncif_proc_get_config_rsp (p_msg);
        break;

    case NCI_MSG_CORE_SET_CONFIG:
        nfc_ncif_set_config_status (pp, len);
        break;

    case NCI_MSG_CORE_CONN_CREATE:
        nfc_ncif_proc_conn_create_rsp (p, p_msg->len, *p_old);
        break;

    case NCI_MSG_CORE_CONN_CLOSE:
        nfc_ncif_report_conn_close_evt (*p_old, *pp);
        break;

    default:
        NFC_TRACE_ERROR1 ("unknown opcode:0x%x", op_code);
        break;
    }

    return free;
}
Exemple #3
0
/*******************************************************************************
**
** Function         nfc_process_timer_evt
**
** Description      Process nfc GKI timer event
**
** Returns          void
**
*******************************************************************************/
void nfc_process_timer_evt (void)
{
    TIMER_LIST_ENT  *p_tle;

    GKI_update_timer_list (&nfc_cb.timer_queue, 1);

    while ((nfc_cb.timer_queue.p_first) && (!nfc_cb.timer_queue.p_first->ticks))
    {
        p_tle = nfc_cb.timer_queue.p_first;
        GKI_remove_from_timer_list (&nfc_cb.timer_queue, p_tle);

        switch (p_tle->event)
        {
        case NFC_TTYPE_NCI_WAIT_RSP:
            nfc_ncif_cmd_timeout();
            break;

        case NFC_TTYPE_WAIT_2_DEACTIVATE:
            nfc_wait_2_deactivate_timeout ();
            break;
        case NFC_TTYPE_NCI_WAIT_DATA_NTF:
        {
            nfc_cb.i2c_data_t.nci_cmd_channel_busy = 0;
            nfc_cb.i2c_data_t.data_stored = 0;
            nfc_ncif_credit_ntf_timeout();
            break;
        }
#if(NFC_NXP_NOT_OPEN_INCLUDED == TRUE)
        case NFC_TTYPE_LISTEN_ACTIVATION:
            {
                extern UINT8 sListenActivated;
                sListenActivated = FALSE;
                nfc_ncif_cmd_timeout();
            }
            break;
#endif

        default:
            NFC_TRACE_DEBUG2 ("nfc_process_timer_evt: timer:0x%x event (0x%04x)", p_tle, p_tle->event);
            NFC_TRACE_DEBUG1 ("nfc_process_timer_evt: unhandled timer event (0x%04x)", p_tle->event);
        }
    }

    /* if timer list is empty stop periodic GKI timer */
    if (nfc_cb.timer_queue.p_first == NULL)
    {
        GKI_stop_timer (NFC_TIMER_ID);
    }
}
/*******************************************************************************
**
** Function         nci_proc_core_ntf
**
** Description      Process NCI notifications in the CORE group
**
** Returns          void
**
*******************************************************************************/
void nci_proc_core_ntf (BT_HDR *p_msg)
{
    UINT8   *p;
    UINT8   *pp, len, op_code;
    UINT8   conn_id;

    /* find the start of the NCI message and parse the NCI header */
    p   = (UINT8 *) (p_msg + 1) + p_msg->offset;
    pp  = p+1;
    NCI_MSG_PRS_HDR1 (pp, op_code);
    NFC_TRACE_DEBUG1 ("nci_proc_core_ntf opcode:0x%x", op_code);
    len = *pp++;

    /* process the message based on the opcode and message type */
    switch (op_code)
    {
    case NCI_MSG_CORE_RESET:
        nfc_ncif_proc_reset_rsp (pp, TRUE);
        break;

    case NCI_MSG_CORE_GEN_ERR_STATUS:
        /* process the error ntf */
        /* in case of timeout: notify the static connection callback */
        nfc_ncif_event_status (NFC_GEN_ERROR_REVT, *pp);
        nfc_ncif_error_status (NFC_RF_CONN_ID, *pp);
        break;

    case NCI_MSG_CORE_INTF_ERR_STATUS:
        conn_id = *(pp+1);
        nfc_ncif_error_status (conn_id, *pp);
        break;

    case NCI_MSG_CORE_CONN_CREDITS:
        nfc_ncif_proc_credits(pp, len);
        break;

    default:
        NFC_TRACE_ERROR1 ("unknown opcode:0x%x", op_code);
        break;
    }
}
/*******************************************************************************
**
** Function         nfc_task
**
** Description      NFC event processing task
**
** Returns          nothing
**
*******************************************************************************/
UINT32 nfc_task (UINT32 param)
{
    UINT16  event;
    BT_HDR  *p_msg;
    BOOLEAN free_buf;

    /* Initialize the nfc control block */
    memset (&nfc_cb, 0, sizeof (tNFC_CB));
    nfc_cb.trace_level = NFC_INITIAL_TRACE_LEVEL;
    nfc_cb.get_nfcc_info = FALSE;


    NFC_TRACE_DEBUG0 ("NFC_TASK started.");

    /* main loop */
    while (TRUE)
    {
        event = GKI_wait (0xFFFF, 0);

        /* Handle NFC_TASK_EVT_TRANSPORT_READY from NFC HAL */
        if (event & NFC_TASK_EVT_TRANSPORT_READY)
        {
            NFC_TRACE_DEBUG0 ("NFC_TASK got NFC_TASK_EVT_TRANSPORT_READY.");

            /* Reset the NFC controller. */
            nfc_set_state (NFC_STATE_CORE_INIT);
            nci_snd_core_reset (NCI_RESET_TYPE_RESET_CFG);
        }

        if (event & NFC_MBOX_EVT_MASK)
        {
            /* Process all incoming NCI messages */
            while ((p_msg = (BT_HDR *) GKI_read_mbox (NFC_MBOX_ID)) != NULL)
            {
                free_buf = TRUE;

                /* Determine the input message type. */
                switch (p_msg->event & BT_EVT_MASK)
                {
                    case BT_EVT_TO_NFC_NCI:
                        if((!nfc_cb.get_nfcc_info))
                        {
                            nfc_task_get_nfcc_info(p_msg);
                            nfc_cb.get_nfcc_info = TRUE;
                        }
                        else
                        {
                            free_buf = nfc_ncif_process_event (p_msg);
                        }

                        break;

                    case BT_EVT_TO_START_TIMER :
                        /* Start nfc_task 1-sec resolution timer */
                        GKI_start_timer (NFC_TIMER_ID, GKI_SECS_TO_TICKS (1), TRUE);
                        break;

                    case BT_EVT_TO_START_QUICK_TIMER :
                        /* Quick-timer is required for LLCP */
                        GKI_start_timer (NFC_QUICK_TIMER_ID, ((GKI_SECS_TO_TICKS (1) / QUICK_TIMER_TICKS_PER_SEC)), TRUE);
                        break;

                    case BT_EVT_TO_NFC_MSGS:
                        nfc_main_handle_hal_evt ((tNFC_HAL_EVT_MSG*)p_msg);
                        break;

                    default:
                        NFC_TRACE_DEBUG1 ("nfc_task: unhandle mbox message, event=%04x", p_msg->event);
                        break;
                }
                /*check if the buffer status is BUF_STATUS_UNLINKED*/
                if (BUF_STATUS_UNLINKED == GKI_getbufstatus(p_msg) && free_buf)
                {
                    GKI_freebuf (p_msg);
                }
            }
        }

        /* Process gki timer tick */
        if (event & NFC_TIMER_EVT_MASK)
        {
            nfc_process_timer_evt ();
        }

        /* Process quick timer tick */
        if (event & NFC_QUICK_TIMER_EVT_MASK)
        {
            nfc_process_quick_timer_evt ();
        }

#if (defined (NFA_INCLUDED) && NFA_INCLUDED == TRUE)
        if (event & NFA_MBOX_EVT_MASK)
        {
            while ((p_msg = (BT_HDR *) GKI_read_mbox (NFA_MBOX_ID)) != NULL)
            {
                nfa_sys_event (p_msg);
            }
        }

        if (event & NFA_TIMER_EVT_MASK)
        {
            nfa_sys_timer_update ();
        }
#endif

    }


    NFC_TRACE_DEBUG0 ("nfc_task terminated");

    return 0;
}
/*****************************************************************************************
**
** Function         nfc_task_get_nfcc_info
**
** Description      Recieves nfcc information coming from nfcc and forward it further to
**                  to nfc service.
**
** Returns          nothing
**
*****************************************************************************************/
void nfc_task_get_nfcc_info(BT_HDR *p_msg)
{
    UINT8 *p = NULL;
    tNFC_RESPONSE   *nfcc_res = NULL;
    UINT32 nfcc_version;

    NFC_TRACE_DEBUG0 ("nfc_task_get_nfcc_info()");

    if(p_msg == NULL)
    {
        NFC_TRACE_DEBUG0 ("NFCC info null");
        return;
    }

    NFC_TRACE_DEBUG0 ("Sending NFCC info");

    p = (UINT8 *) (p_msg + 1) + p_msg->offset;

    nfa_dm_cb.nfcc_version = p[NFCC_CHIP_VERSION_OFFSET];

    switch(nfa_dm_cb.nfcc_version)
    {
        case NFCC_V_20:
           break;
        case NFCC_V_21:
           break;
        case NFCC_V_24:
           break;
        case NFCC_V_30:
           break;
        default:
           NFC_TRACE_DEBUG0 ("Wrong nfcc version.Read from conf file");
           GetNumValue("NFCC_VERSION", &nfcc_version, sizeof(nfcc_version));
           if(nfcc_version)
           {
               nfa_dm_cb.nfcc_version = nfcc_version;
           }
           else
           {
               /*default 3.0*/
               nfa_dm_cb.nfcc_version = NFCC_V_30;
           }
           break;
    }

    NFC_TRACE_DEBUG1 ("nfa_dm_cb.nfcc_version = %d",nfa_dm_cb.nfcc_version);

    nfcc_res = (tNFC_RESPONSE*)malloc(sizeof(tNFC_RESPONSE));
    if(nfcc_res != NULL)
    {
        nfcc_res->nfcc_info_data.len = p_msg->len;
        nfcc_res->nfcc_info_data.value = (UINT8*)malloc( nfcc_res->nfcc_info_data.len);
        if(nfcc_res->nfcc_info_data.value != NULL)
        {
            if(nfcc_res->nfcc_info_data.len != 0)
            {
                memcpy(nfcc_res->nfcc_info_data.value,p,nfcc_res->nfcc_info_data.len);
                if (nfc_cb.p_resp_cback)
                {
                    (*nfc_cb.p_resp_cback) (NFC_NFCC_INFO_REVT, nfcc_res);
                }
            }
            /*free acquired mem*/
            free(nfcc_res->nfcc_info_data.value);
            nfcc_res->nfcc_info_data.value = NULL;
        }
        else
        {
            NFC_TRACE_DEBUG0 ("Memory allocation failed");
        }
        /*free acquired mem*/
        free(nfcc_res);
        nfcc_res = NULL;
    }
    else
    {
        NFC_TRACE_DEBUG0 ("Memory allocation failed for nfcc_res");
    }
}
/*******************************************************************************
**
** Function         nci_proc_ee_management_ntf
**
** Description      Process NCI notifications in the NFCEE Management group
**
** Returns          void
**
*******************************************************************************/
void nci_proc_ee_management_ntf (BT_HDR *p_msg)
{
    UINT8                 *p;
    UINT8                 *pp, len, op_code;
    tNFC_RESPONSE_CBACK   *p_cback = nfc_cb.p_resp_cback;
    tNFC_NFCEE_INFO_REVT  nfcee_info;
    tNFC_RESPONSE         *p_evt   = (tNFC_RESPONSE *) &nfcee_info;
    tNFC_RESPONSE_EVT     event    = NFC_NFCEE_INFO_REVT;
    UINT8                 xx;
    UINT8                 yy;
    UINT8                 ee_status;
    tNFC_NFCEE_TLV        *p_tlv;

    /* find the start of the NCI message and parse the NCI header */
    p   = (UINT8 *) (p_msg + 1) + p_msg->offset;
    pp  = p+1;
    NCI_MSG_PRS_HDR1 (pp, op_code);
    NFC_TRACE_DEBUG1 ("nci_proc_ee_management_ntf opcode:0x%x", op_code);
    len = *pp++;

    if (op_code == NCI_MSG_NFCEE_DISCOVER)
    {
        nfcee_info.nfcee_id    = *pp++;
        ee_status                   = *pp++;

        nfcee_info.ee_status        = ee_status;
        yy                          = *pp;
        nfcee_info.num_interface    = *pp++;
        p                           = pp;

        if (nfcee_info.num_interface > NFC_MAX_EE_INTERFACE)
            nfcee_info.num_interface = NFC_MAX_EE_INTERFACE;

        for (xx = 0; xx < nfcee_info.num_interface; xx++)
        {
            nfcee_info.ee_interface[xx] = *pp++;
        }

        pp                              = p + yy;
        nfcee_info.num_tlvs             = *pp++;
        NFC_TRACE_DEBUG4 ("nfcee_id: 0x%x num_interface:0x%x/0x%x, num_tlvs:0x%x",
            nfcee_info.nfcee_id, nfcee_info.num_interface, yy, nfcee_info.num_tlvs);

        if (nfcee_info.num_tlvs > NFC_MAX_EE_TLVS)
            nfcee_info.num_tlvs = NFC_MAX_EE_TLVS;

        p_tlv = &nfcee_info.ee_tlv[0];

        for (xx = 0; xx < nfcee_info.num_tlvs; xx++, p_tlv++)
        {
            p_tlv->tag  = *pp++;
            p_tlv->len  = yy = *pp++;
            NFC_TRACE_DEBUG2 ("tag:0x%x, len:0x%x", p_tlv->tag, p_tlv->len);
            if (p_tlv->len > NFC_MAX_EE_INFO)
                p_tlv->len = NFC_MAX_EE_INFO;
            p   = pp;
            STREAM_TO_ARRAY (p_tlv->info, pp, p_tlv->len);
            pp  = p += yy;
        }
    }
    else
    {
        p_cback = NULL;
        NFC_TRACE_ERROR1 ("unknown opcode:0x%x", op_code);
    }

    if (p_cback)
        (*p_cback) (event, p_evt);
}
Exemple #8
0
/*******************************************************************************
**
** Function         nfc_process_quick_timer_evt
**
** Description      Process quick timer event
**
** Returns          void
**
*******************************************************************************/
void nfc_process_quick_timer_evt (void)
{
    TIMER_LIST_ENT  *p_tle;

    GKI_update_timer_list (&nfc_cb.quick_timer_queue, 1);

    while ((nfc_cb.quick_timer_queue.p_first) && (!nfc_cb.quick_timer_queue.p_first->ticks))
    {
        p_tle = nfc_cb.quick_timer_queue.p_first;
        GKI_remove_from_timer_list (&nfc_cb.quick_timer_queue, p_tle);

        switch (p_tle->event)
        {
#if (NFC_RW_ONLY == FALSE)
        case NFC_TTYPE_LLCP_LINK_MANAGER:
        case NFC_TTYPE_LLCP_LINK_INACT:
        case NFC_TTYPE_LLCP_DATA_LINK:
        case NFC_TTYPE_LLCP_DELAY_FIRST_PDU:
            llcp_process_timeout (p_tle);
            break;
#endif
        case NFC_TTYPE_RW_T1T_RESPONSE:
            rw_t1t_process_timeout (p_tle);
            break;
        case NFC_TTYPE_RW_T2T_RESPONSE:
            rw_t2t_process_timeout (p_tle);
            break;
        case NFC_TTYPE_RW_T3T_RESPONSE:
            rw_t3t_process_timeout (p_tle);
            break;
        case NFC_TTYPE_RW_T4T_RESPONSE:
            rw_t4t_process_timeout (p_tle);
            break;
        case NFC_TTYPE_RW_I93_RESPONSE:
            rw_i93_process_timeout (p_tle);
            break;
#if(NFC_NXP_NOT_OPEN_INCLUDED == TRUE)
        case NFC_TTYPE_P2P_PRIO_RESPONSE:
            nfa_dm_p2p_timer_event ();
            break;
        case NFC_TTYPE_P2P_PRIO_LOGIC_CLEANUP:
            nfa_dm_p2p_prio_logic_cleanup();
            break;
#endif
#if (NFC_RW_ONLY == FALSE)
        case NFC_TTYPE_CE_T4T_UPDATE:
            ce_t4t_process_timeout (p_tle);
            break;
#endif
        default:
            NFC_TRACE_DEBUG1 ("nfc_process_quick_timer_evt: unhandled timer event (0x%04x)", p_tle->event);
            break;
        }
    }

    /* if timer list is empty stop periodic GKI timer */
    if (nfc_cb.quick_timer_queue.p_first == NULL)
    {
        GKI_stop_timer (NFC_QUICK_TIMER_ID);
    }
}