static
NFCSTATUS
phHciNfc_SWP_InfoUpdate(
                                phHciNfc_sContext_t     *psHciContext,
                                uint8_t                 index,
                                uint8_t                 *reg_value,
                                uint8_t                 reg_length
                          )
{
    phHciNfc_SWP_Info_t         *ps_swp_info=NULL;
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;

    ps_swp_info = (phHciNfc_SWP_Info_t *)
                    psHciContext->p_swp_info ;

    /* To remove "warning (VS C4100) : unreferenced formal parameter" */
    PHNFC_UNUSED_VARIABLE(reg_length);
    switch(index)
    {
        case NXP_SWP_DEFAULT_MODE_INDEX:
        {
            HCI_PRINT_BUFFER("\tUICC Enable Register:",reg_value,reg_length);
            break;
        } 
            /* Get the Status of the UICC Connection */
        case NXP_SWP_STATUS_INDEX:
        {
            HCI_PRINT_BUFFER("\tUICC Connection Status:", reg_value, reg_length);
            ps_swp_info->uicc_status = (phHciNfc_SWP_Status_t ) *reg_value ;
            break;
        }
        case NXP_SWP_PROTECTED_INDEX:
        {
            HCI_PRINT_BUFFER("\t UICC Card Emulation Rights :",reg_value,reg_length);

            break;
        }
        default:
        {
            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
            break;
        }
    } /* End of switch(index) */
    
    return status;
}
Exemplo n.º 2
0
static
NFCSTATUS
phHciNfc_Recv_Felica_Packet(
                            phHciNfc_sContext_t  *psHciContext,
                            uint8_t              cmd,
                            uint8_t              *pResponse,
#ifdef ONE_BYTE_LEN
                            uint8_t             length
#else
                            uint16_t            length
#endif
                            )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    uint8_t                     index = 0;

    /* To remove "warning (VS C4100) : unreferenced formal parameter" */

    PHNFC_UNUSED_VARIABLE(length);

    if (NXP_FELICA_RAW == cmd)
    {
        if (FELICA_STATUS == pResponse[index])  /* Status byte */
        {
            index = (index + 1);
            psHciContext->rx_index = (HCP_HEADER_LEN + 1);
            HCI_PRINT_BUFFER("Felica Bytes received", &pResponse[index], (length - index));
        }
        else
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                                NFCSTATUS_INVALID_HCI_RESPONSE);
        }
    } 
    else
    {
        psHciContext->rx_index = HCP_HEADER_LEN;

        /* command NXP_FELICA_CMD: so give Felica data to the upper layer */
        HCI_PRINT_BUFFER("Felica Bytes received", pResponse, length);
    }

    return status;
}
/*Timer callback for recv data timer for CE.This timer is used for creating
  Asynchronous behavior in the scenario where the data is received even before
  the upper layer calls the phHal4Nfc_receive().*/
void phHal4Nfc_CE_RecvTimerCb(uint32_t CERecvTimerId, void *pContext)
{
    phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)(
                                            gpphHal4Nfc_Hwref->hal_context);
    pphLibNfc_TransceiveCallback_t pUpperRecvCb = NULL;
    NFCSTATUS RecvDataBufferStatus = NFCSTATUS_PENDING;
    PHNFC_UNUSED_VARIABLE(pContext);

    phOsalNfc_Timer_Stop(CERecvTimerId);
    phOsalNfc_Timer_Delete(CERecvTimerId);
    if(NULL != Hal4Ctxt->psTrcvCtxtInfo)
    {
        RecvDataBufferStatus = Hal4Ctxt->psTrcvCtxtInfo->RecvDataBufferStatus;
        Hal4Ctxt->psTrcvCtxtInfo->RecvDataBufferStatus = NFCSTATUS_PENDING;

        Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId
            = PH_OSALNFC_INVALID_TIMER_ID;
        /*Update state*/
        Hal4Ctxt->Hal4NextState = (eHal4StateTransaction
             == Hal4Ctxt->Hal4NextState?eHal4StateInvalid:Hal4Ctxt->Hal4NextState);
        /*Provide address of received data to upper layer data pointer*/
        Hal4Ctxt->psTrcvCtxtInfo->psUpperRecvData
            = &(Hal4Ctxt->psTrcvCtxtInfo->sLowerRecvData);
        /*Chk NULL and call recv callback*/
        if(Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb != NULL)
        {
            pUpperRecvCb = (pphLibNfc_TransceiveCallback_t)Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb;
            Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb = NULL;
            (*pUpperRecvCb)(
                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
                Hal4Ctxt->sTgtConnectInfo.psConnectedDevice,
                Hal4Ctxt->psTrcvCtxtInfo->psUpperRecvData,
                RecvDataBufferStatus
                );
        }
    }
    return;
}
NFCSTATUS phLibNfc_Llcp_DiscoverServices( phLibNfc_Handle     hRemoteDevice,
                                          phNfc_sData_t       *psServiceNameList,
                                          uint8_t             *pnSapList,
                                          uint8_t             nListSize,
                                          pphLibNfc_RspCb_t   pDiscover_Cb,
                                          void                *pContext
                                          )
{
   NFCSTATUS                           result;
   PHNFC_UNUSED_VARIABLE(hRemoteDevice);

   PH_LOG_LLCP_FUNC_ENTRY();

   result = static_CheckState();
   if (result != NFCSTATUS_SUCCESS)
   {
      PH_LOG_LLCP_FUNC_EXIT();
      return result;
   }

   if ((hRemoteDevice == 0)       ||
       (psServiceNameList == NULL) ||
       (pnSapList == NULL) ||
       (nListSize == 0) ||
       (pDiscover_Cb == NULL))
   {
      PH_LOG_LLCP_FUNC_EXIT();
      return NFCSTATUS_INVALID_PARAMETER;
   }

   result = static_CheckDevice(hRemoteDevice);
   if (result != NFCSTATUS_SUCCESS)
   {
      PH_LOG_LLCP_FUNC_EXIT();
      return result;
   }

   /* Prepare callback */
   gpphLibNfc_Context->CBInfo.pClientLlcpDiscoveryCb = pDiscover_Cb;
   gpphLibNfc_Context->CBInfo.pClientLlcpDiscoveryCntx = pContext;

   /* Call the component function */
   result = phFriNfc_LlcpTransport_DiscoverServices( &gpphLibNfc_Context->llcp_cntx.sLlcpTransportContext,
                                                     psServiceNameList,
                                                     pnSapList,
                                                     nListSize,
                                                     pDiscover_Cb,
                                                     pContext
                                                     );
   result = PHNFCSTATUS(result);
   if ((result == NFCSTATUS_PENDING) || (result == NFCSTATUS_SUCCESS))
   {
      /* Nothing to do */
   }
   else if (result != NFCSTATUS_FAILED)
   {
      result = NFCSTATUS_TARGET_LOST;
   }

   PH_LOG_LLCP_FUNC_EXIT();
   return result;
}
Exemplo n.º 5
0
static 
void 
phLlcNfc_ConnectionTimeoutCb (
    uint32_t TimerId,
    void *pContext
)
{
    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
    phNfc_sCompletionInfo_t     notifyinfo = {0};
    pphNfcIF_Notification_CB_t  notifyul = NULL;
    void                        *p_upperctxt = NULL;
    phLlcNfc_Frame_t            *ps_frame_info = NULL;
    phLlcNfc_Timerinfo_t        *ps_timer_info = NULL;
    PHNFC_UNUSED_VARIABLE(pContext);
    
    PH_LLCNFC_PRINT("\n\nLLC : CONNECTION TIMEOUT CB CALLED\n\n");
    if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == 
        gpphLlcNfc_Ctxt->s_timerinfo.timer_id[PH_LLCNFC_CONNECTIONTIMER]) 
        && (PH_LLCNFC_CON_TO_BIT_VAL == 
        (gpphLlcNfc_Ctxt->s_timerinfo.timer_flag & 
        PH_LLCNFC_CON_TO_BIT_VAL)))
    {
        ps_frame_info = &(gpphLlcNfc_Ctxt->s_frameinfo);
        ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);
        if (ps_timer_info->con_to_value > 0)
        {
#if !defined (CYCLIC_TIMER)
            phOsalNfc_Timer_Stop(
                    ps_timer_info->timer_id[PH_LLCNFC_CONNECTIONTIMER]);
            /* phLlcNfc_StopTimers(PH_LLCNFC_CONNECTIONTIMER, 0); */
#endif
            ps_timer_info->con_to_value = 0;
        
            if (0 == ps_timer_info->con_to_value)
            {
                PH_LLCNFC_DEBUG("TIMER EXPIRED RETRY COUNT : %02X\n", ps_frame_info->retry_cnt);
                phLlcNfc_StopTimers (PH_LLCNFC_CONNECTIONTIMER, 0);
                
                if (ps_frame_info->retry_cnt < PH_LLCNFC_MAX_RETRY_COUNT)
                {
                    /* Create a U frame */
                    result = phLlcNfc_H_CreateUFramePayload(gpphLlcNfc_Ctxt, 
                                        &(ps_frame_info->s_llcpacket),
                                        &(ps_frame_info->s_llcpacket.llcbuf_len), 
                                        phLlcNfc_e_rset);

                    if (NFCSTATUS_SUCCESS == result)
                    {
                        /* Call DAL write */
                        result = phLlcNfc_Interface_Write (gpphLlcNfc_Ctxt, 
                                (uint8_t*)&(ps_frame_info->s_llcpacket.s_llcbuf), 
                                (uint32_t)(ps_frame_info->s_llcpacket.llcbuf_len));
                    }
                    if (NFCSTATUS_PENDING == result)
                    {
                        /* Start the timer */
                        result = phLlcNfc_StartTimers(PH_LLCNFC_CONNECTIONTIMER, 0);
                        if (NFCSTATUS_SUCCESS == result)
                        {
                            ps_frame_info->retry_cnt++;
                            result = NFCSTATUS_PENDING;
                        }
                    }
                    else
                    {
                        if (NFCSTATUS_BUSY == PHNFCSTATUS(result))
                        {
                            result = NFCSTATUS_PENDING;
                        }
                    }
                }
                else
                {
                    PH_LLCNFC_PRINT("RETRY COUNT LIMIT REACHED \n");
                    if ((ps_frame_info->retry_cnt == PH_LLCNFC_MAX_RETRY_COUNT) 
                        && (NULL != gpphLlcNfc_Ctxt->cb_for_if.notify))
                    {
                        void            *p_hw_info = NULL;
                        uint8_t         type = 0;
                        
                        p_hw_info = gpphLlcNfc_Ctxt->phwinfo;
                        notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC, 
                                            NFCSTATUS_BOARD_COMMUNICATION_ERROR);
                        
                        notifyul = gpphLlcNfc_Ctxt->cb_for_if.notify;
                        p_upperctxt = gpphLlcNfc_Ctxt->cb_for_if.pif_ctxt;
                        type = NFC_NOTIFY_ERROR;
                        if (init_u_rset_frame == ps_frame_info->sent_frame_type)
                        {
                            type = NFC_NOTIFY_INIT_FAILED;
                            /* Release if, the initialisation is not complete */
                            result = phLlcNfc_Release(gpphLlcNfc_Ctxt, p_hw_info);
                            gpphLlcNfc_Ctxt = NULL;
                        }
                        else
                        {
                            type = NFC_NOTIFY_DEVICE_ERROR;
                            notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC, 
                                            NFCSTATUS_BOARD_COMMUNICATION_ERROR);
#if 0
                            phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); 
#endif /* #if 0 */
                        }
                        /* Notify the upper layer */
                        notifyul(p_upperctxt, p_hw_info, type, &notifyinfo);
                    }
                }
            }
#if !defined (CYCLIC_TIMER)
            else
            {
                /* Start the timer again */
                phOsalNfc_Timer_Start(
                            ps_timer_info->timer_id[PH_LLCNFC_CONNECTIONTIMER], 
                            ps_timer_info->con_to_value, phLlcNfc_ConnectionTimeoutCb, NULL);
            }
#endif
        }
    }
    PH_LLCNFC_PRINT("\n\nLLC : CONNECTION TIMEOUT CB END\n\n");
}
Exemplo n.º 6
0
static 
void 
phLlcNfc_GuardTimeoutCb (
    uint32_t TimerId,
    void *pContext
)
{
    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
    phLlcNfc_Timerinfo_t        *ps_timer_info = NULL;
    phLlcNfc_Frame_t            *ps_frame_info = NULL;
    phLlcNfc_LlcPacket_t        *ps_packet_info = NULL;
    uint8_t                     index = 0;
    uint8_t                     zero_to_index = 0;
#if defined (GUARD_TO_ERROR)
    phNfc_sCompletionInfo_t     notifyinfo = {0};
#endif /* #if defined (GUARD_TO_ERROR) */
    PHNFC_UNUSED_VARIABLE(pContext);

    PH_LLCNFC_PRINT("\n\nLLC : GUARD TIMEOUT CB CALLED \n\n");

    if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == 
        gpphLlcNfc_Ctxt->s_timerinfo.timer_id[PH_LLCNFC_GUARDTIMER]) && 
        (PH_LLCNFC_GUARD_TO_BIT_VAL == 
        (gpphLlcNfc_Ctxt->s_timerinfo.timer_flag & 
        PH_LLCNFC_GUARD_TO_BIT_VAL)))
    {
        uint8_t                 timer_expired = FALSE;
        ps_frame_info = &(gpphLlcNfc_Ctxt->s_frameinfo);
        ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);

#if !defined (CYCLIC_TIMER)
        phOsalNfc_Timer_Stop(
                    ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER]);
#endif

        PH_LLCNFC_DEBUG("NO OF TIMEOUT COUNT : 0x%02X\n", ps_timer_info->guard_to_count);
        /* Loop is completely depending on the number of different LLC  
           send called */
        while (index < ps_timer_info->guard_to_count) 
        {
            if (0 != ps_timer_info->guard_to_value[index])
            {
                if (ps_timer_info->guard_to_value[index] > 0)
                {
                    if (ps_timer_info->guard_to_value[index] >= 
                        PH_LLCNFC_RESOLUTION)
                    {
                        ps_timer_info->guard_to_value[index] = (uint16_t)
                            (ps_timer_info->guard_to_value[index] - 
                            PH_LLCNFC_RESOLUTION);
                    }
                    else
                    {
                        ps_timer_info->guard_to_value[index] = 0;
                    }
                }

                if (0 == ps_timer_info->guard_to_value[index])
                {
                    zero_to_index = index;
                    timer_expired = TRUE;
                }
            }
            index = (uint8_t)(index + 1);
        }

#if !defined (CYCLIC_TIMER)        
        /* Start the timer again */
        phOsalNfc_Timer_Start(
                    ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER], 
                    PH_LLCNFC_RESOLUTION, phLlcNfc_GuardTimeoutCb, NULL);
#endif
        PH_LLCNFC_DEBUG("TIMER EXPIRED : 0x%02X\n", timer_expired);        

        if (TRUE == timer_expired)
        {
            PH_LLCNFC_DEBUG("TIMER EXPIRED INDEX: 0x%02X\n", zero_to_index);
            PH_LLCNFC_DEBUG("TIMER EXPIRED NS INDEX: 0x%02X\n", ps_timer_info->timer_ns_value[zero_to_index]);
            PH_LLCNFC_DEBUG("TIMER EXPIRED RETRIES : 0x%02X\n", ps_timer_info->iframe_send_count[zero_to_index]);

            PH_LLCNFC_DEBUG("TIMER EXPIRED GUARD TIME-OUT COUNT: 0x%02X\n", ps_timer_info->guard_to_value[zero_to_index]);

            if ((0 == ps_timer_info->guard_to_value[zero_to_index]) && 
                (ps_timer_info->iframe_send_count[zero_to_index] < 
                LLC_GUARD_TIMER_RETRIES))
            {
                if (ps_frame_info->s_send_store.winsize_cnt > 0)
                {
                    uint8_t             start_index = 0;
                    uint8_t             timer_count = 0;
                    uint8_t             while_exit = FALSE;

                    timer_count = ps_timer_info->guard_to_count;

                    
                    /* Check before changing the index to resend, if index 
                        already exist then dont set the index */
                    while ((FALSE == while_exit) && (start_index < timer_count))
                    {
                        if (resend_i_frame == 
                            ps_timer_info->frame_type[start_index])
                        {
                            while_exit = TRUE;
                        }
                        else
                        {                     
                            start_index = (uint8_t)(start_index + 1);
                        }
                    }

                    if (TRUE == while_exit)
                    {
                        ps_timer_info->index_to_send = zero_to_index;
                    }

                    ps_timer_info->frame_type[zero_to_index] = (uint8_t)
                                                            resend_i_frame;
                    /* Now resend the frame stored */
                    result = phLlcNfc_H_SendTimedOutIFrame (gpphLlcNfc_Ctxt, 
                                            &(ps_frame_info->s_send_store), 
                                            0);
                }
            }
            else
            {
                if ((LLC_GUARD_TIMER_RETRIES == 
                    ps_timer_info->iframe_send_count[zero_to_index]) && 
                    (NULL != gpphLlcNfc_Ctxt->cb_for_if.notify))
                {
                    phLlcNfc_StopAllTimers ();
#if defined (GUARD_TO_ERROR)
                    
                    notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC, 
                                        NFCSTATUS_BOARD_COMMUNICATION_ERROR);
#if 0
                    phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); 
#endif /* #if 0 */
                    /* Resend done, no answer from the device */
                    gpphLlcNfc_Ctxt->cb_for_if.notify (
                                    gpphLlcNfc_Ctxt->cb_for_if.pif_ctxt,
                                    gpphLlcNfc_Ctxt->phwinfo, 
                                    NFC_NOTIFY_DEVICE_ERROR, 
                                    &notifyinfo);

#endif /* #if defined (GUARD_TO_ERROR) */

#if (!defined (GUARD_TO_ERROR) && defined (GUARD_TO_URSET))

                    PH_LLCNFC_PRINT("U-RSET IS SENT \n");
                    ps_packet_info = &(gpphLlcNfc_Ctxt->s_frameinfo.s_llcpacket);

                    result = phLlcNfc_H_CreateUFramePayload(gpphLlcNfc_Ctxt, 
                                        ps_packet_info, 
                                        &(ps_packet_info->llcbuf_len), 
                                        phLlcNfc_e_rset);

                    result = phLlcNfc_Interface_Write(gpphLlcNfc_Ctxt, 
                                    (uint8_t*)&(ps_packet_info->s_llcbuf), 
                                    (uint32_t)ps_packet_info->llcbuf_len);

                    ps_frame_info->write_status = result;
                    if (NFCSTATUS_PENDING == result)
                    {
                        /* Start the timer */
                        result = phLlcNfc_StartTimers (PH_LLCNFC_CONNECTIONTIMER, 0);
                        if (NFCSTATUS_SUCCESS == result)
                        {
                            ps_frame_info->retry_cnt = 0;
                            gpphLlcNfc_Ctxt->s_frameinfo.sent_frame_type = 
                                                                    u_rset_frame;
                            result = NFCSTATUS_PENDING;
                        }
                    }
                    else
                    {
                        if (NFCSTATUS_BUSY == PHNFCSTATUS (result))
                        {                        
                            ps_frame_info->write_wait_call = u_rset_frame;
                        }
                    }

#endif /* #if defined (GUARD_TO_ERROR) */
                }
            }
        }
    }
    PH_LLCNFC_PRINT("\n\nLLC : GUARD TIMEOUT CB END\n\n");
}
Exemplo n.º 7
0
void 
phLlcNfc_StopTimers (
    uint8_t             TimerType, 
    uint8_t             no_of_guard_to_del
)
{
    NFCSTATUS               result = NFCSTATUS_SUCCESS;
#ifdef LLC_TIMER_ENABLE

    uint32_t                timerid = 0,
                            timerflag = FALSE;
    uint8_t                 timer_count = 0;
    phLlcNfc_Timerinfo_t    *ps_timer_info = NULL;
    

    ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);
    timerflag = ps_timer_info->timer_flag;

    PHNFC_UNUSED_VARIABLE (result);
    PH_LLCNFC_PRINT("\n\nLLC : STOP TIMER CALLED\n\n");
    switch(TimerType)
    {
        case PH_LLCNFC_CONNECTIONTIMER:
        {           
            ps_timer_info->timer_flag = (uint8_t)
                        SET_BITS8(ps_timer_info->timer_flag, 
                                PH_LLCNFC_CON_TO_BIT, 
                                PH_LLCNFC_TO_NOOFBITS, 0);
            timerid = ps_timer_info->timer_id
                                [PH_LLCNFC_CONNECTION_TO_INDEX];
            break;
        }

        case PH_LLCNFC_GUARDTIMER:
        {
            uint8_t             start_index = 0;

            timer_count = ps_timer_info->guard_to_count;

            PH_LLCNFC_DEBUG("GUARD TIMER COUNT BEFORE DELETE: 0x%02X\n", timer_count);
            PH_LLCNFC_DEBUG("GUARD TIMER TO DELETE: 0x%02X\n", no_of_guard_to_del);

            if (timer_count > no_of_guard_to_del)
            {
                /* The number of guard timer count is more than the 
                    guard timer to delete  */
                while (start_index < no_of_guard_to_del)
                {
                    /* Copy the previous stored timer values to the present */
                    ps_timer_info->guard_to_value[start_index] = (uint16_t)
                                (ps_timer_info->guard_to_value[
                                (no_of_guard_to_del + start_index)]);

                    ps_timer_info->iframe_send_count[start_index] = (uint8_t)
                                (ps_timer_info->iframe_send_count[
                                (no_of_guard_to_del + start_index)]);

                    PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX DELETED : 0x%02X\n", ps_timer_info->timer_ns_value[start_index]);

                    ps_timer_info->timer_ns_value[start_index] = (uint8_t)
                                (ps_timer_info->timer_ns_value[
                                (no_of_guard_to_del + start_index)]);

                    ps_timer_info->frame_type[start_index] = (uint8_t)
                                (ps_timer_info->frame_type[
                                (no_of_guard_to_del + start_index)]);

                    start_index = (uint8_t)(start_index + 1);
                }
            }
            else
            {
                while (start_index < no_of_guard_to_del)
                {
                    ps_timer_info->guard_to_value[start_index] = 0;

                    ps_timer_info->iframe_send_count[start_index] = 0;

                    PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX DELETED ELSE : 0x%02X\n", ps_timer_info->timer_ns_value[start_index]);

                    ps_timer_info->timer_ns_value[start_index] = 0;

                    ps_timer_info->frame_type[start_index] = 0;

                    start_index = (uint8_t)(start_index + 1);
                }
            }

            if (timer_count >= no_of_guard_to_del)
            {
                timer_count = (uint8_t)(timer_count - no_of_guard_to_del);
            }
            else
            {
                if (0 != no_of_guard_to_del)
                {
                    timer_count = 0;
                }
            }

            timerid = ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER];
            ps_timer_info->guard_to_count = timer_count;
            PH_LLCNFC_DEBUG("GUARD TIMER COUNT AFTER DELETE: 0x%02X\n", timer_count);

            if (0 == ps_timer_info->guard_to_count)
            {
                /* This means that there are no frames to run guard 
                    timer, so set the timer flag to 0 */
                ps_timer_info->timer_flag = (uint8_t)
                        SET_BITS8 (ps_timer_info->timer_flag, 
                                    PH_LLCNFC_GUARD_TO_BIT, 
                                    PH_LLCNFC_TO_NOOFBITS, 0);
            }
            else
            {
                timerflag = 0;
            }
            break;
        }  

#ifdef PIGGY_BACK
        case PH_LLCNFC_ACKTIMER:
        {
            ps_timer_info->timer_flag = (uint8_t)
                                SET_BITS8 (ps_timer_info->timer_flag, 
                                        PH_LLCNFC_GUARD_TO_BIT, 
                                        PH_LLCNFC_TO_NOOFBITS, 0);
            timerid = ps_timer_info->timer_id[PH_LLCNFC_ACKTIMER];
            break;
        }
#endif /* #ifdef PIGGY_BACK */

        default:
        {
            result = PHNFCSTVAL(CID_NFC_LLC, 
                                NFCSTATUS_INVALID_PARAMETER);
            break;
        }
    }

    if ((NFCSTATUS_SUCCESS == result) && (timerflag > 0))
    {
        PH_LLCNFC_DEBUG("OSAL STOP TIMER CALLED TIMER ID : 0x%02X\n", timerid);
        phOsalNfc_Timer_Stop (timerid);
    }

    PH_LLCNFC_PRINT("\n\nLLC : STOP TIMER END\n\n");

#else /* #ifdef LLC_TIMER_ENABLE */

    PHNFC_UNUSED_VARIABLE (result);
    PHNFC_UNUSED_VARIABLE (TimerType);
    PHNFC_UNUSED_VARIABLE (no_of_gaurd_to_del);

#endif /* #ifdef LLC_TIMER_ENABLE */
}
Exemplo n.º 8
0
NFCSTATUS 
phLlcNfc_StartTimers (
    uint8_t             TimerType, 
    uint8_t             ns_value
)
{
    NFCSTATUS               result = NFCSTATUS_SUCCESS;
#ifdef LLC_TIMER_ENABLE

    uint32_t                timerid = 0;
    uint8_t                 timerstarted = 0;
    uint8_t                 timer_count = 0;
    uint16_t                timer_resolution = 0;
    ppCallBck_t             Callback = NULL;
    phLlcNfc_Timerinfo_t    *ps_timer_info = NULL;

    ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);
    PHNFC_UNUSED_VARIABLE(result);

    PH_LLCNFC_PRINT("\n\nLLC : START TIMER CALLED\n\n");
    /* Depending on the timer type, use the Osal callback */
    switch(TimerType)
    {
        case PH_LLCNFC_CONNECTIONTIMER:
        {
            /* Get the connection timer flag */
            timerstarted = (uint8_t)
                GET_BITS8(ps_timer_info->timer_flag, 
                        PH_LLCNFC_CON_TO_BIT, 
                        PH_LLCNFC_TO_NOOFBITS);
            if (0 == timerstarted)
            {
                /* Timer not started, so start the timer */
                gpphLlcNfc_Ctxt->s_timerinfo.timer_flag = (uint8_t)
                                SET_BITS8 (ps_timer_info->timer_flag,
                                        PH_LLCNFC_CON_TO_BIT, 
                                        PH_LLCNFC_TO_NOOFBITS, 
                                        (PH_LLCNFC_CON_TO_BIT + 1));
            }
            
            timerid = ps_timer_info->timer_id[PH_LLCNFC_CONNECTION_TO_INDEX];
            Callback = (ppCallBck_t)&phLlcNfc_ConnectionTimeoutCb;
            timer_resolution = ps_timer_info->con_to_value = (uint16_t)
                                            PH_LLCNFC_CONNECTION_TO_VALUE;
            break;
        }

        case PH_LLCNFC_GUARDTIMER:
        {
            if (ps_timer_info->guard_to_count < PH_LLCNFC_MAX_GUARD_TIMER)
            {
                timer_count = ps_timer_info->guard_to_count;
                timer_resolution = (uint16_t)PH_LLCNFC_RESOLUTION;

                PH_LLCNFC_DEBUG("RESOLUTION VALUE : 0x%02X\n", PH_LLCNFC_RESOLUTION);
                PH_LLCNFC_DEBUG("TIME-OUT VALUE : 0x%02X\n", PH_LLCNFC_GUARD_TO_VALUE);
                
                /* Get the guard timer flag */
                timerstarted = (uint8_t)
                    GET_BITS8 (ps_timer_info->timer_flag, 
                            PH_LLCNFC_GUARD_TO_BIT, 
                            PH_LLCNFC_TO_NOOFBITS);

                PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX : 0x%02X\n", ns_value);
                PH_LLCNFC_DEBUG("GUARD TIMER COUNT : 0x%02X\n", timer_count);
                PH_LLCNFC_DEBUG("GUARD TIMER STARTED : 0x%02X\n", timerstarted);

                if (0 == timerstarted)
                {
                    /* Timer not started, so start the timer */
                    ps_timer_info->timer_flag = (uint8_t)
                        SET_BITS8 (ps_timer_info->timer_flag,
                                    PH_LLCNFC_GUARD_TO_BIT, 
                                    PH_LLCNFC_TO_NOOFBITS, 
                                    PH_LLCNFC_GUARD_TO_BIT);
                }
                
                timerid = ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER];
                Callback = (ppCallBck_t)&phLlcNfc_GuardTimeoutCb;

                /* Guard time out value */
                ps_timer_info->guard_to_value[timer_count] = (uint16_t)
                                        PH_LLCNFC_GUARD_TO_VALUE;

                ps_timer_info->timer_ns_value[timer_count] = ns_value;
                ps_timer_info->frame_type[timer_count] = (uint8_t)invalid_frame;
                ps_timer_info->iframe_send_count[timer_count] = 0;

                if ((timer_count > 0) && 
                    (ps_timer_info->guard_to_value[(timer_count - 1)] >= 
                    PH_LLCNFC_GUARD_TO_VALUE))
                {
                    /* If the timer has been started already and the 
                        value is same as the previous means that timer has still 
                        not expired, so the time out value is increased by 
                        a resolution */
                    ps_timer_info->guard_to_value[timer_count] = (uint16_t)
                            (ps_timer_info->guard_to_value[(timer_count - 1)] + 
                            PH_LLCNFC_RESOLUTION);
                }

                PH_LLCNFC_DEBUG("GUARD TIMER VALUE : 0x%04X\n", ps_timer_info->guard_to_value[timer_count]);

                
                ps_timer_info->guard_to_count = (uint8_t)(
                                        ps_timer_info->guard_to_count + 1);
            }
            else
            {
                /* TIMER should not start, because the time out count has readched the limit */
                timerstarted = TRUE;
            }
            break;
        }
        
#ifdef PIGGY_BACK

        case PH_LLCNFC_ACKTIMER:
        {
            /* Get the ack timer flag */
            timerstarted = (uint8_t)GET_BITS8 (
                                    ps_timer_info->timer_flag, 
                                    PH_LLCNFC_GUARD_TO_BIT, 
                                    PH_LLCNFC_TO_NOOFBITS);
            if (0 == timerstarted)
            {
                /* Timer not started, so start the timer */
                ps_timer_info->timer_flag = (uint8_t)
                                SET_BITS8 (ps_timer_info->timer_flag, 
                                        PH_LLCNFC_GUARD_TO_BIT
                                        PH_LLCNFC_TO_NOOFBITS
                                        (PH_LLCNFC_GUARD_TO_BIT - 1));
            }
            timerid = ps_timer_info->timer_id[PH_LLCNFC_ACKTIMER];
            Callback = (ppCallBck_t)&phLlcNfc_AckTimeoutCb;
            break;
        }

#endif /* #ifdef PIGGY_BACK */

        default:
        {
            result = PHNFCSTVAL(CID_NFC_LLC, 
                                NFCSTATUS_INVALID_PARAMETER);
            break;
        }
    }
    if ((NFCSTATUS_SUCCESS == result) && 
        (FALSE == timerstarted))
    {
        PH_LLCNFC_DEBUG("OSAL START TIMER CALLED TIMER ID : 0x%02X\n", timerid);
        phOsalNfc_Timer_Start (timerid, timer_resolution, Callback, NULL);
    }

    PH_LLCNFC_PRINT("\n\nLLC : START TIMER END\n\n");

#else /* #ifdef LLC_TIMER_ENABLE */

    PHNFC_UNUSED_VARIABLE(result);
    PHNFC_UNUSED_VARIABLE(TimerType);
    PHNFC_UNUSED_VARIABLE(ns_value);    

#endif /* #ifdef LLC_TIMER_ENABLE */
    return result;
}
Exemplo n.º 9
0
/* shutdown callback -
  Free the allocated memory here */
STATIC void phLibNfc_ShutdownCb(void *pContext,NFCSTATUS status)
{
    pphLibNfc_RspCb_t           pClientCb=NULL;
    void                        *pUpperLayerContext=NULL;
    pphLibNfc_LibContext_t      pLibContext=NULL;

    PHNFC_UNUSED_VARIABLE(pContext);
    /* Get the Lib context */
    pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;

    if(pLibContext == NULL)
    {
        status = NFCSTATUS_FAILED;
    }
    else
    {
        /* Initialize the local variable */
        pClientCb =pLibContext->CBInfo.pClientShutdownCb;
        pUpperLayerContext=pLibContext->CBInfo.pClientShtdwnCntx;
        if(status == NFCSTATUS_SUCCESS)
        {
            pLibContext->LibNfcState.cur_state = eLibNfcHalStateShutdown;
            phLibNfc_UpdateCurState(status,pLibContext);

            pLibContext->status.GenCb_pending_status=FALSE;
            
            /* Allocate the Memory for the Transceive info */
            if(pClientCb!=NULL)
            {
                (*pClientCb)(pUpperLayerContext, status);
            }
            if(pLibContext->psHwReference!=NULL)
            {
                phOsalNfc_FreeMemory(pLibContext->psHwReference);
                pLibContext->psHwReference = NULL;
            }
            if(NULL != gpphLibContext->psBufferedAuth)
            {
                if(NULL != gpphLibContext->psBufferedAuth->sRecvData.buffer)
                {
                    phOsalNfc_FreeMemory(
                        gpphLibContext->psBufferedAuth->sRecvData.buffer);
                }
                if(NULL != gpphLibContext->psBufferedAuth->sSendData.buffer)
                {
                    phOsalNfc_FreeMemory(
                        gpphLibContext->psBufferedAuth->sSendData.buffer);
                }
                phOsalNfc_FreeMemory(gpphLibContext->psBufferedAuth);
                gpphLibContext->psBufferedAuth = NULL;
            }
            /*Free the memory allocated during NDEF read,write
              and NDEF formatting*/
            phLibNfc_Ndef_DeInit();        
                phOsalNfc_FreeMemory(pLibContext);
                gpphLibContext=NULL;
                pLibContext= NULL;
       
        }
        else
        {
            /* shutdown sequence failed by HAL 4 */
            status= NFCSTATUS_FAILED;
            pLibContext=(pphLibNfc_LibContext_t)gpphLibContext;
            phLibNfc_UpdateCurState(status,pLibContext);
            pLibContext->status.GenCb_pending_status=FALSE;
            if(pClientCb!=NULL)
            {
                (*pClientCb)(pUpperLayerContext,status);
            }
        }
    }
}
NFCSTATUS phFriNfc_OvrHal_Transceive(phFriNfc_OvrHal_t              *OvrHal,
                                     phFriNfc_CplRt_t               *CompletionInfo,
                                     phHal_sRemoteDevInformation_t  *RemoteDevInfo,
                                     phHal_uCmdList_t                Cmd,
                                     phHal_sDepAdditionalInfo_t     *DepAdditionalInfo,
                                     uint8_t                        *SendBuf,
                                     uint16_t                        SendLength,
                                     uint8_t                        *RecvBuf,
                                     uint16_t                       *RecvLength)
{
    NFCSTATUS status = NFCSTATUS_PENDING;
    uint8_t i = 0;
    uint32_t length = SendLength;

    /* To remove "warning (VS C4100) : unreferenced formal parameter" */
    PHNFC_UNUSED_VARIABLE(DepAdditionalInfo);

    /* Check the Input Parameters */
    if ((NULL == OvrHal) || (NULL == CompletionInfo) || (NULL == RemoteDevInfo)
        || (NULL == (void*)SendBuf) || (NULL == RecvBuf) || (NULL == RecvLength) 
        || ((phHal_eJewel_PICC != RemoteDevInfo->RemDevType) && (0 == SendLength)))

    {
        status = PHNFCSTVAL(CID_FRI_NFC_OVR_HAL, NFCSTATUS_INVALID_PARAMETER);
    }
    else
    {
        /* 16 is the maximum data, that can be sent to the mifare standard */
        static uint8_t      mif_send_buf[MAX_MIF_PACKET_LEN] = {0};
        /* Populate the Transfer info structure */
        OvrHal->TranceiveInfo.cmd = Cmd;
     
        /* Populate the Send Buffer Info */
        if((phHal_eMifare_PICC == RemoteDevInfo->RemDevType) 
            || (phHal_eISO14443_3A_PICC == RemoteDevInfo->RemDevType))
        {
            OvrHal->TranceiveInfo.addr = SendBuf[i++];
            length = (SendLength - i);

            if ((phHal_eMifareAuthentA == Cmd.MfCmd) 
                || (phHal_eMifareAuthentB == Cmd.MfCmd))
            {
                uint8_t     uid_index = 0;
                /* Authentication requires UID in the send buffer */
                uint8_t     uid_len = 
                        RemoteDevInfo->RemoteDevInfo.Iso14443A_Info.UidLength;
                OvrHal->TranceiveInfo.sSendData.buffer = mif_send_buf;

                switch (uid_len)
                {
                    case MIFARE_PLUS_UID_LENGTH:
                    {
                        uid_index = MIFARE_PLUS_UID_INDEX_TO_COPY;
                        uid_len = MIFARE_UID_LEN_TO_COPY;
                        break;
                    }

                    case MIFARE_CLASSIC_UID_LENGTH:
                    {
                        uid_index = 0;
                        break;
                    }

                    default:
                    {
                        status = PHNFCSTVAL (CID_FRI_NFC_OVR_HAL, 
                                            NFCSTATUS_READ_FAILED);                                            
                        break;
                    }
                }

                if (NFCSTATUS_PENDING == status)
                {
                    /* copy uid to the send buffer for the authentication */
                    (void)memcpy ((void *)mif_send_buf, 
                        (void *)&RemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Uid[uid_index], 
                        uid_len);

                    (void)memcpy((mif_send_buf + uid_len), &(SendBuf[i]), length);
                    length += uid_len;
                }
            }
            else
            {
                OvrHal->TranceiveInfo.sSendData.buffer = &SendBuf[i++];         
            }           
            OvrHal->TranceiveInfo.sSendData.length = length;
        }
        else
        {
            OvrHal->TranceiveInfo.sSendData.buffer = &SendBuf[i++];
            OvrHal->TranceiveInfo.sSendData.length = length;
        }
        
        if (NFCSTATUS_PENDING == status)
        {
            /* Populate the Receive buffer */
            OvrHal->TranceiveInfo.sRecvData.buffer = RecvBuf;
            OvrHal->TranceiveInfo.sRecvData.length = *RecvLength;
            OvrHal->pndef_recv_length = RecvLength;
            phFriNfc_OvrHal_SetComplInfo(OvrHal,CompletionInfo, PH_FRINFC_OVRHAL_TRX);
            
            /* Call the HAL 4.0 Transceive Function */
            status = phHal4Nfc_Transceive (OvrHal->psHwReference, 
                                            &OvrHal->TranceiveInfo, RemoteDevInfo, 
                                            phFriNfc_OvrHal_CB_Transceive, (void *)OvrHal);
        }

    }
    return status;  

}
Exemplo n.º 11
0
static
NFCSTATUS
phHciNfc_Recv_Felica_Packet(
                            phHciNfc_sContext_t  *psHciContext,
                            uint8_t              cmd,
                            uint8_t              *pResponse,
#ifdef ONE_BYTE_LEN
                            uint8_t             length
#else
                            uint16_t            length
#endif
                            )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    uint8_t                     index = 0;

    /* To remove "warning (VS C4100) : unreferenced formal parameter" */

    PHNFC_UNUSED_VARIABLE(length);

    if (NXP_FELICA_RAW == cmd)
    {
        if (FELICA_STATUS == pResponse[index])  /* Status byte */
        {
            index = (index + 1);
            psHciContext->rx_index = (HCP_HEADER_LEN + 1);
            HCI_PRINT_BUFFER("Felica Bytes received", &pResponse[index], (length - index));
            /* If Poll response received then update IDm and PMm parameters, when presence check going on */
            if (pResponse[index + 1] == 0x01)
            {
                if (length >= 19)
                {
                    /* IDm */
                    (void) memcpy(psHciContext->p_target_info->RemoteDevInfo.Felica_Info.IDm,
                                  &pResponse[index + 2], 8);
                    /* PMm */
                    (void) memcpy(psHciContext->p_target_info->RemoteDevInfo.Felica_Info.PMm,
                                  &pResponse[index + 2 + 8], 8);
                    index = index + 2 + 8 + 8;

                    /* SC */
                    if (length >= 21)
                    {
                        /* Copy SC if available */
                        psHciContext->p_target_info->RemoteDevInfo.Felica_Info.SystemCode[0] = pResponse[index];
                        psHciContext->p_target_info->RemoteDevInfo.Felica_Info.SystemCode[1] = pResponse[index + 1];
                    }
                    else
                    {
                        /* If SC is not available in packet then set to zero */
                        psHciContext->p_target_info->RemoteDevInfo.Felica_Info.SystemCode[0] = 0;
                        psHciContext->p_target_info->RemoteDevInfo.Felica_Info.SystemCode[1] = 0;
                    }
                }
                else
                {
                    status = PHNFCSTVAL(CID_NFC_HCI,
                                        NFCSTATUS_INVALID_HCI_RESPONSE);
                }
            }
        }
        else
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                                NFCSTATUS_INVALID_HCI_RESPONSE);
        }
    } 
    else
    {
        psHciContext->rx_index = HCP_HEADER_LEN;

        /* command NXP_FELICA_CMD: so give Felica data to the upper layer */
        HCI_PRINT_BUFFER("Felica Bytes received", pResponse, length);
    }

    return status;
}
Exemplo n.º 12
0
/**
* Callback for Se Set mode 
*/
STATIC void phLibNfc_SE_SetMode_cb(void  *context, NFCSTATUS status)
{
    pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)context;
    pphLibNfc_SE_SetModeRspCb_t  pUpperLayerCb=NULL;
    void                         *pUpperContext=NULL;
    phLibNfc_Handle              hSeHandle=0;
    uint8_t                      TempState=FALSE;  

    if(pLibContext != gpphLibContext)
    {
        /*wrong context returned*/
        phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1);
    }
    else
    {
        if(eLibNfcHalStateShutdown == gpphLibContext->LibNfcState.next_state)
        {
            /*If shutdown is called in between allow shutdown to happen*/
            phLibNfc_Pending_Shutdown();
            status = NFCSTATUS_SHUTDOWN;
        }
        else
        {
            if(status == NFCSTATUS_SUCCESS)
            {
                hSeHandle = pLibContext->sSeContext.hSetemp;       

                if(hSeHandle == sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].hSecureElement)
                {
                    if(TRUE==pLibContext->sCardEmulCfg.config.uiccEmuCfg.enableUicc)
                    {
                        /*If  Activation mode was virtual allow external reader to see it*/
                        pLibContext->sSeContext.uUiccActivate = TRUE;
                        sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState = phLibNfc_SE_Active;
                    }
                    else
                    {
                        /*If  Activation mode was wired don't allow external reader to see it*/
                        pLibContext->sSeContext.uUiccActivate = FALSE;
                        sSecuredElementInfo[LIBNFC_SE_UICC_INDEX].eSE_CurrentState =
                                                                    phLibNfc_SE_Inactive;
                    }
                    status = NFCSTATUS_SUCCESS;                    
                    TempState = pLibContext->sSeContext.uUiccActivate;
                }
                else if (hSeHandle==sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].hSecureElement)
                {
                    if(TRUE==pLibContext->sCardEmulCfg.config.smartMxCfg.enableEmulation)
                    {
                        /*If  Activation mode was virtual allow external reader to see it*/
                        pLibContext->sSeContext.uSmxActivate = TRUE;
                        sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState = 
                                                                        phLibNfc_SE_Active; 
                    }
                    else
                    {
                        /*If  Activation mode was wired don't allow external reader to see it*/
                        pLibContext->sSeContext.uSmxActivate = FALSE;                        
                        sSecuredElementInfo[LIBNFC_SE_SMARTMX_INDEX].eSE_CurrentState=
                                                                        phLibNfc_SE_Inactive; 
                    }
                    status = NFCSTATUS_SUCCESS;                    
                    TempState = pLibContext->sSeContext.uSmxActivate;
                }
                else
                {
                    status = NFCSTATUS_FAILED;
                }
            }
            else
            {
                status = NFCSTATUS_FAILED;
            }
            pLibContext->status.GenCb_pending_status = FALSE; 
        }
        
    }
    pUpperLayerCb = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb;
    pUpperContext = pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt;  
    pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCb = NULL;
    pLibContext->sSeContext.sSeCallabackInfo.pSEsetModeCtxt = NULL;
	PHNFC_UNUSED_VARIABLE(TempState);
    /* Call the upper layer cb */
    if(pUpperLayerCb!= NULL )
    {
        (*pUpperLayerCb)(pUpperContext,                        
                        hSeHandle,
						status);
    }
    return;
}