Exemplo n.º 1
0
/*******************************************************************************
**
** Function         RW_T4tReadNDef
**
** Description      This function performs NDEF read procedure
**                  Note: RW_T4tDetectNDef () must be called before using this
**
**                  The following event will be returned
**                      RW_T4T_NDEF_READ_EVT for each segmented NDEF message
**                      RW_T4T_NDEF_READ_CPLT_EVT for the last segment or complete NDEF
**                      RW_T4T_NDEF_READ_FAIL_EVT for failure
**
** Returns          NFC_STATUS_OK if success
**                  NFC_STATUS_FAILED if T4T is busy or other error
**
*******************************************************************************/
tNFC_STATUS RW_T4tReadNDef (void)
{
    RW_TRACE_API0 ("RW_T4tReadNDef ()");

    if (rw_cb.tcb.t4t.state != RW_T4T_STATE_IDLE)
    {
        RW_TRACE_ERROR1 ("RW_T4tReadNDef ():Unable to start command at state (0x%X)",
                          rw_cb.tcb.t4t.state);
        return NFC_STATUS_FAILED;
    }

    /* if NDEF has been detected */
    if (rw_cb.tcb.t4t.ndef_status & RW_T4T_NDEF_STATUS_NDEF_DETECTED)
    {
        /* start reading NDEF */
        if (!rw_t4t_read_file (T4T_FILE_LENGTH_SIZE, rw_cb.tcb.t4t.ndef_length, FALSE))
        {
            return NFC_STATUS_FAILED;
        }

        rw_cb.tcb.t4t.state     = RW_T4T_STATE_READ_NDEF;
        rw_cb.tcb.t4t.sub_state = RW_T4T_SUBSTATE_WAIT_READ_RESP;

        return NFC_STATUS_OK;
    }
    else
    {
        RW_TRACE_ERROR0 ("RW_T4tReadNDef ():No NDEF detected");
        return NFC_STATUS_FAILED;
    }
}
Exemplo n.º 2
0
/*******************************************************************************
**
** Function         RW_T4tDetectNDef
**
** Description      This function performs NDEF detection procedure
**
**                  RW_T4T_NDEF_DETECT_EVT will be returned
**
** Returns          NFC_STATUS_OK if success
**                  NFC_STATUS_FAILED if T4T is busy or other error
**
*******************************************************************************/
tNFC_STATUS RW_T4tDetectNDef (void)
{
    RW_TRACE_API0 ("RW_T4tDetectNDef ()");

    if (rw_cb.tcb.t4t.state != RW_T4T_STATE_IDLE)
    {
        RW_TRACE_ERROR1 ("RW_T4tDetectNDef ():Unable to start command at state (0x%X)",
                          rw_cb.tcb.t4t.state);
        return NFC_STATUS_FAILED;
    }

    if (rw_cb.tcb.t4t.ndef_status & RW_T4T_NDEF_STATUS_NDEF_DETECTED)
    {
        /* NDEF Tag application has been selected then select CC file */
        if (!rw_t4t_select_file (T4T_CC_FILE_ID))
        {
            return NFC_STATUS_FAILED;
        }
        rw_cb.tcb.t4t.sub_state = RW_T4T_SUBSTATE_WAIT_SELECT_CC;
    }
    else
    {
        /* Select NDEF Tag Application */
        if (!rw_t4t_select_application (rw_cb.tcb.t4t.version))
        {
            return NFC_STATUS_FAILED;
        }
        rw_cb.tcb.t4t.sub_state = RW_T4T_SUBSTATE_WAIT_SELECT_APP;
    }

    rw_cb.tcb.t4t.state     = RW_T4T_STATE_DETECT_NDEF;

    return NFC_STATUS_OK;
}
Exemplo n.º 3
0
/*******************************************************************************
**
** Function         RW_T1tReadAll
**
** Description      This function sends a RALL command for Reader/Writer mode.
**
** Returns          tNFC_STATUS
**
*******************************************************************************/
tNFC_STATUS RW_T1tReadAll (void)
{
    tRW_T1T_CB  *p_t1t  = &rw_cb.tcb.t1t;
    tNFC_STATUS status  = NFC_STATUS_FAILED;

    RW_TRACE_API0 ("RW_T1tReadAll");

    if (p_t1t->state != RW_T1T_STATE_IDLE)
    {
        RW_TRACE_WARNING1 ("RW_T1tReadAll - Busy - State: %u", p_t1t->state);
        return (NFC_STATUS_BUSY);
    }

    /* send RALL command */
    if ((status = rw_t1t_send_static_cmd (T1T_CMD_RALL, 0, 0)) == NFC_STATUS_OK)
    {
        p_t1t->state = RW_T1T_STATE_READ;
    }

    return status;
}
Exemplo n.º 4
0
/*****************************************************************************
**
** Function         RW_T4tPresenceCheck
**
** Description
**      Check if the tag is still in the field.
**
**      The RW_T4T_PRESENCE_CHECK_EVT w/ status is used to indicate presence
**      or non-presence.
**
** Returns
**      NFC_STATUS_OK, if raw data frame sent
**      NFC_STATUS_NO_BUFFERS: unable to allocate a buffer for this operation
**      NFC_STATUS_FAILED: other error
**
*****************************************************************************/
tNFC_STATUS RW_T4tPresenceCheck (void)
{
    tNFC_STATUS retval = NFC_STATUS_OK;
    tRW_DATA    evt_data;

    RW_TRACE_API0 ("RW_T4tPresenceCheck ()");

    /* If RW_SelectTagType was not called (no conn_callback) return failure */
    if (!rw_cb.p_cback)
    {
        retval = NFC_STATUS_FAILED;
    }
    /* If we are not activated, then RW_T4T_PRESENCE_CHECK_EVT with NFC_STATUS_FAILED */
    else if (rw_cb.tcb.t4t.state == RW_T4T_STATE_NOT_ACTIVATED)
    {
        evt_data.status = NFC_STATUS_FAILED;
        (*rw_cb.p_cback) (RW_T4T_PRESENCE_CHECK_EVT, &evt_data);
    }
    /* If command is pending, assume tag is still present */
    else if (rw_cb.tcb.t4t.state != RW_T4T_STATE_IDLE)
    {
        evt_data.status = NFC_STATUS_OK;
        (*rw_cb.p_cback) (RW_T3T_PRESENCE_CHECK_EVT, &evt_data);
    }
    else
    {
        if (rw_t4t_read_file (0, 1, FALSE))
        {
            rw_cb.tcb.t4t.state = RW_T4T_STATE_PRESENCE_CHECK;
        }
        else
        {
            retval = NFC_STATUS_NO_BUFFERS;
        }
    }

    return (retval);
}
Exemplo n.º 5
0
/*****************************************************************************
**
** Function         RW_T2tPresenceCheck
**
** Description
**      Check if the tag is still in the field.
**
**      The RW_T2T_PRESENCE_CHECK_EVT w/ status is used to indicate presence
**      or non-presence.
**
** Returns
**      NFC_STATUS_OK, if raw data frame sent
**      NFC_STATUS_NO_BUFFERS: unable to allocate a buffer for this operation
**      NFC_STATUS_FAILED: other error
**
*****************************************************************************/
tNFC_STATUS RW_T2tPresenceCheck (void)
{
    tNFC_STATUS retval = NFC_STATUS_OK;
    tRW_DATA evt_data;
    tRW_CB *p_rw_cb = &rw_cb;
    UINT8 sector_blk = 0;           /* block 0 of current sector */

    RW_TRACE_API0 ("RW_T2tPresenceCheck");

    /* If RW_SelectTagType was not called (no conn_callback) return failure */
    if (!p_rw_cb->p_cback)
    {
        retval = NFC_STATUS_FAILED;
    }
    /* If we are not activated, then RW_T2T_PRESENCE_CHECK_EVT status=FAIL */
    else if (p_rw_cb->tcb.t2t.state == RW_T2T_STATE_NOT_ACTIVATED)
    {
        evt_data.status = NFC_STATUS_FAILED;
        (*p_rw_cb->p_cback) (RW_T2T_PRESENCE_CHECK_EVT, &evt_data);
    }
    /* If command is pending, assume tag is still present */
    else if (p_rw_cb->tcb.t2t.state != RW_T2T_STATE_IDLE)
    {
        evt_data.status = NFC_STATUS_OK;
        (*p_rw_cb->p_cback) (RW_T2T_PRESENCE_CHECK_EVT, &evt_data);
    }
    else
    {
        /* IDLE state: send a READ command to block 0 of the current sector */
        if((retval = rw_t2t_send_cmd (T2T_CMD_READ, &sector_blk))== NFC_STATUS_OK)
        {
            p_rw_cb->tcb.t2t.state = RW_T2T_STATE_CHECK_PRESENCE;
        }
    }

    return (retval);
}
Exemplo n.º 6
0
/*****************************************************************************
**
** Function         RW_T1tPresenceCheck
**
** Description
**      Check if the tag is still in the field.
**
**      The RW_T1T_PRESENCE_CHECK_EVT w/ status is used to indicate presence
**      or non-presence.
**
** Returns
**      NFC_STATUS_OK, if raw data frame sent
**      NFC_STATUS_NO_BUFFERS: unable to allocate a buffer for this operation
**      NFC_STATUS_FAILED: other error
**
*****************************************************************************/
tNFC_STATUS RW_T1tPresenceCheck (void)
{
    tNFC_STATUS retval = NFC_STATUS_OK;
    tRW_DATA evt_data;
    tRW_CB *p_rw_cb = &rw_cb;

    RW_TRACE_API0 ("RW_T1tPresenceCheck");

    /* If RW_SelectTagType was not called (no conn_callback) return failure */
    if (!p_rw_cb->p_cback)
    {
        retval = NFC_STATUS_FAILED;
    }
    /* If we are not activated, then RW_T1T_PRESENCE_CHECK_EVT status=FAIL */
    else if (p_rw_cb->tcb.t1t.state == RW_T1T_STATE_NOT_ACTIVATED)
    {
        evt_data.status = NFC_STATUS_FAILED;
        (*p_rw_cb->p_cback) (RW_T1T_PRESENCE_CHECK_EVT, &evt_data);
    }
    /* If command is pending, assume tag is still present */
    else if (p_rw_cb->tcb.t1t.state != RW_T1T_STATE_IDLE)
    {
        evt_data.status = NFC_STATUS_OK;
        (*p_rw_cb->p_cback) (RW_T1T_PRESENCE_CHECK_EVT, &evt_data);
    }
    else
    {
        /* IDLE state: send a RID command to the tag to see if it responds */
        if((retval = rw_t1t_send_static_cmd (T1T_CMD_RID, 0, 0))== NFC_STATUS_OK)
        {
            p_rw_cb->tcb.t1t.state = RW_T1T_STATE_CHECK_PRESENCE;
        }
    }

    return (retval);
}