Ejemplo n.º 1
0
void nativeNfcSnep_stopServer()
{
    NXPLOG_API_D ("%s:", __FUNCTION__);
    gSyncMutex.lock();
    if (!nativeNfcManager_isNfcActive())
    {
        NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__);
        gSyncMutex.unlock();
        return;
    }

    nativeNfcSnep_abortServerWaits();
    sServerCallback = NULL;

    sRfEnabled = isDiscoveryStarted();
    if (sRfEnabled)
    {
        // Stop RF Discovery if we were polling
        startRfDiscovery (FALSE);
    }
    NFA_SnepDeregister(sSnepServerHandle);
    if (sRfEnabled)
    {
        startRfDiscovery (TRUE);
    }
    sSnepServerState = SNEP_SERVER_IDLE;
    gSyncMutex.unlock();
}
Ejemplo n.º 2
0
void nativeNfcSnep_deregisterClientCallback()
{
    NXPLOG_API_D ("%s:", __FUNCTION__);

    gSyncMutex.lock();
    if (!nativeNfcManager_isNfcActive())
    {
        NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__);
        gSyncMutex.unlock();
        return;
    }
    nativeNfcSnep_abortClientWaits();
    sRfEnabled = isDiscoveryStarted();
    if (sRfEnabled)
    {
        // Stop RF Discovery if we were polling
        startRfDiscovery (FALSE);
    }
    NFA_SnepDeregister(sSnepClientHandle);
    sClientCallback = NULL;
    if (sRfEnabled)
    {
        startRfDiscovery (TRUE);
    }
    gSyncMutex.unlock();
}
Ejemplo n.º 3
0
int nfcManager_doAppletLoadApplet(JNIEnv* e, jobject o, jstring name, jbyteArray data)
{
    (void)e;
    (void)o;
    (void)name;
#if (NFC_NXP_ESE == TRUE && ALA_VERSION_2 == FALSE)
    ALOGD ("%s: enter", __FUNCTION__);
    tNFA_STATUS wStatus, status;
    IChannel_t Dwp;
    bool stat = false;
    const char *choice = NULL;

    sRfEnabled = isDiscoveryStarted();
    wStatus = status = NFA_STATUS_FAILED;

    set_transcation_stat(true);
    if (sRfEnabled) {
        // Stop RF Discovery if we were polling
        startRfDiscovery (false);
    }
    DWPChannel_init(&Dwp);
    wStatus = ALA_Init(&Dwp);
    if(wStatus != NFA_STATUS_OK)
    {
        ALOGE("%s: ALA initialization failed", __FUNCTION__);
    }
    else
    {
        ALOGE("%s: start Applet load applet", __FUNCTION__);
        choice = e->GetStringUTFChars(name, 0);
        ALOGE("choice= %s", choice);
        ScopedByteArrayRO bytes(e, data);
        uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0]));
        size_t bufLen = bytes.size();
        wStatus = ALA_Start(choice, buf, bufLen);
    }
    stat = ALA_DeInit();
    if(choice != NULL)
        e->ReleaseStringUTFChars(name, choice);

    if(dwpChannelForceClose == false)
        startRfDiscovery (true);

    set_transcation_stat(false);

    ALOGD ("%s: exit; status =0x%X", __FUNCTION__,wStatus);
#else

    tNFA_STATUS wStatus = 0x0F;
    ALOGD ("%s: No p61", __FUNCTION__);
#endif
    return wStatus;

}
Ejemplo n.º 4
0
/*******************************************************************************
**
** Function:        nfcManager_lsGetVersion
**
** Description:     It is ued to get version of Loader service client & Applet
**                  e: JVM environment.
**                  o: Java object.
**
** Returns:         version of Loder service.
**
*******************************************************************************/
jbyteArray nfcManager_lsGetVersion(JNIEnv* e, jobject)
{

#if (NFC_NXP_ESE == TRUE && ALA_VERSION_2 == TRUE)
    ALOGD ("%s: enter", __FUNCTION__);
    tNFA_STATUS wStatus = NFA_STATUS_FAILED;
    IChannel_t Dwp;
    bool stat = false;
    const INT32 recvBufferMaxSize = 4;
    UINT8 recvBuffer [recvBufferMaxSize];

    sRfEnabled = isDiscoveryStarted();
    set_transcation_stat(true);
    if (sRfEnabled) {
        // Stop RF Discovery if we were polling
        startRfDiscovery (false);
    }
    DWPChannel_init(&Dwp);
    wStatus = ALA_Init(&Dwp);
    if(wStatus != NFA_STATUS_OK)
    {
        ALOGE("%s: ALA initialization failed", __FUNCTION__);
    }
    else
    {
        ALOGE("%s: start Get reference Certificate Key", __FUNCTION__);
        wStatus = ALA_lsGetVersion(recvBuffer);
    }

    //copy results back to java
    jbyteArray result = e->NewByteArray(recvBufferMaxSize);
    if (result != NULL)
    {
        e->SetByteArrayRegion(result, 0, recvBufferMaxSize, (jbyte *) recvBuffer);
    }

    stat = ALA_DeInit();
    if(dwpChannelForceClose == false)
        startRfDiscovery (true);

    set_transcation_stat(false);

    ALOGD("%s: exit: recv len=%ld", __FUNCTION__, recvBufferMaxSize);
#else
    jbyteArray result = e->NewByteArray(0);
    ALOGD ("%s: No p61", __FUNCTION__);
#endif
    return result;

}
Ejemplo n.º 5
0
/*******************************************************************************
**
** Function:        nfcManager_GetListofApplets
**
** Description:     provides the list of applets present in the directory.
**                  e: JVM environment.
**                  o: Java object.
**
** Returns:         None.
**
*******************************************************************************/
int nfcManager_GetAppletsList(JNIEnv* e, jobject o, jobjectArray list)
{
    (void)e;
    (void)o;
    (void)list;
#if (NFC_NXP_ESE == TRUE && ALA_VERSION_2 == FALSE)
    char *name[10];
    UINT8 num =0, xx=0;
    UINT8 list_len = e->GetArrayLength(list);
    ALOGD ("%s: enter", __FUNCTION__);

    sRfEnabled = isDiscoveryStarted();
    if (sRfEnabled) {
        // Stop RF Discovery if we were polling
        startRfDiscovery (false);
    }
    ALOGD("%s: list_len=0x%x", __FUNCTION__, list_len);
    ALA_GetlistofApplets(name, &num);

    if((num != 0) &&
       (list_len >= num))
    {
        while(num > 0)
        {
            jstring tmp = e->NewStringUTF(name[xx]);
            e->SetObjectArrayElement(list, xx, tmp);
            if(name[xx] != NULL)
            {
                free(name[xx]);
            }
            xx++;
            num--;
        }
    }
    else
    {
        ALOGE("%s: No applets found",__FUNCTION__);
    }
    startRfDiscovery (true);
#else
    int xx = -1;
    ALOGD ("%s: No p61", __FUNCTION__);
#endif
    ALOGD ("%s: exit; num_applets =0x%X", __FUNCTION__,xx);
    return xx;
}
Ejemplo n.º 6
0
INT32 nativeNfcLlcp_ConnLessRegisterClientCallback(nfcllcpConnlessClientCallback_t *clientCallback)
{
    tNFA_STATUS status = NFA_STATUS_FAILED;
    pthread_t llcpCleintRespThread;
    int ret = 1;
    NXPLOG_API_D ("%s:", __FUNCTION__);

    gSyncMutex.lock();
    if (!nativeNfcManager_isNfcActive())
    {
        NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__);
        gSyncMutex.unlock();
        return NFA_STATUS_FAILED;
    }

    sRfEnabled = isDiscoveryStarted();
    if (sRfEnabled)
    {
        /* Stop RF Discovery if we were polling */
        startRfDiscovery (FALSE);
    }

    {
        SyncEventGuard g (sNfaLlcpClientRegEvent);
        bClientReadState = FALSE;
        if(NFA_STATUS_OK != (status = NFA_P2pRegisterClient(NFA_P2P_LLINK_TYPE, nfaLlcpClientCallback)))
        {
            NXPLOG_API_E ("%s: fail to register client callback for LLCP", __FUNCTION__);
            if (sRfEnabled)
            {
                /*  Rollback to default */
                startRfDiscovery (TRUE);
                gSyncMutex.unlock();
                return status;
            }

        }
        sNfaLlcpClientRegEvent.wait();
    }

    sClientCallback = clientCallback;
    status = NFA_STATUS_OK;

    gSyncMutex.unlock();
    return status;
}
Ejemplo n.º 7
0
INT32 nativeNfcSnep_registerClientCallback(nfcSnepClientCallback_t *clientCallback)
{
    tNFA_STATUS status = NFA_STATUS_FAILED;
    NXPLOG_API_D ("%s:", __FUNCTION__);
    gSyncMutex.lock();
    if (!nativeNfcManager_isNfcActive())
    {
        NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__);
        gSyncMutex.unlock();
        return NFA_STATUS_FAILED;
    }
    sRfEnabled = isDiscoveryStarted();
    if (sRfEnabled)
    {
        // Stop RF Discovery if we were polling
        startRfDiscovery (FALSE);
    }
    {
        SyncEventGuard g (sNfaSnepClientRegEvent);
        if(NFA_STATUS_OK != (status = NFA_SnepRegisterClient(nfaSnepClientCallback)))
        {
            NXPLOG_API_E ("%s: fail to register client callback for SNEP", __FUNCTION__);
            goto clean_and_return;
        }
        sNfaSnepClientRegEvent.wait();
    }
    sClientCallback = clientCallback;
    status = NFA_STATUS_OK;
clean_and_return:
    if (sRfEnabled)
    {
        // Stop RF Discovery if we were polling
        startRfDiscovery (TRUE);
    }
    gSyncMutex.unlock();
    return status;
}
Ejemplo n.º 8
0
/*******************************************************************************
**
** Function:        nfcManager_lsExecuteScript
**
** Description:     start jcos download.
**                  e: JVM environment.
**                  o: Java object.
**                  name: path of the ALA script file located
**                  data: SHA encrypted package name
**
** Returns:         True if ok.
**
*******************************************************************************/
jbyteArray nfcManager_lsExecuteScript(JNIEnv* e, jobject o, jstring name, jstring dest, jbyteArray data)
{
    (void)e;
    (void)o;
    (void)name;
    (void)dest;
    const char *destpath = NULL;
    const UINT8 lsExecuteResponseSize = 4;
    uint8_t resSW [4]={0x4e,0x02,0x69,0x87};
    jbyteArray result = e->NewByteArray(0);
#if (NFC_NXP_ESE == TRUE && ALA_VERSION_2 == TRUE)
    ALOGD ("%s: enter", __FUNCTION__);
    tNFA_STATUS wStatus, status;
    IChannel_t Dwp;
    bool stat = false;
    const char *choice = NULL;

    sRfEnabled = isDiscoveryStarted();
    wStatus = status = NFA_STATUS_FAILED;

    set_transcation_stat(true);
    if (sRfEnabled) {
        // Stop RF Discovery if we were polling
        startRfDiscovery (false);
    }
    DWPChannel_init(&Dwp);
    wStatus = ALA_Init(&Dwp);
    if(wStatus != NFA_STATUS_OK)
    {
        ALOGE("%s: ALA initialization failed", __FUNCTION__);
    }
    else
    {
        // Commented the Disabling standby
        /* UINT8 param[] = {0x00}; //Disable standby
        SyncEventGuard guard (sNfaVSCResponseEvent);
        status = NFA_SendVsCommand (0x00,0x01,param,nfaVSCCallback);
        if(NFA_STATUS_OK == status)
        {
            sNfaVSCResponseEvent.wait(); //wait for NFA VS command to finish
            ALOGE("%s: start Applet load applet", __FUNCTION__);
            choice = e->GetStringUTFChars(name, 0);
            ALOGE("choice= %s", choice);
            wStatus = ALA_Start(choice);
        }*/
        destpath = e->GetStringUTFChars(dest, 0);
        ALOGE("destpath= %s", destpath);
        ALOGE("%s: start Applet load applet", __FUNCTION__);
        choice = e->GetStringUTFChars(name, 0);
        ALOGE("choice= %s", choice);
        ScopedByteArrayRO bytes(e, data);
        uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0]));
        size_t bufLen = bytes.size();
        wStatus = ALA_Start(choice,destpath, buf, bufLen,resSW);

       //copy results back to java
       result = e->NewByteArray(lsExecuteResponseSize);
       if (result != NULL)
       {
           e->SetByteArrayRegion(result, 0, lsExecuteResponseSize, (jbyte *) resSW);
       }
    }

    // Commented the Enabling standby
    /* UINT8 param[] = {0x01}; //Enable standby
    SyncEventGuard guard (sNfaVSCResponseEvent);
    status = NFA_SendVsCommand (0x00,0x01,param,nfaVSCCallback);
    if(NFA_STATUS_OK == status)
    {
        sNfaVSCResponseEvent.wait(); //wait for NFA VS command to finish
    }*/

    stat = ALA_DeInit();
    if(choice != NULL)
        e->ReleaseStringUTFChars(name, choice);

    if(dwpChannelForceClose == false)
        startRfDiscovery (true);

    set_transcation_stat(false);

    ALOGD ("%s: exit; status =0x%X", __FUNCTION__,wStatus);
#else
    if(destpath != NULL)
        e->ReleaseStringUTFChars(dest, destpath);

    result = e->NewByteArray(0);
    tNFA_STATUS wStatus = 0x0F;
    ALOGD ("%s: No p61", __FUNCTION__);
#endif
    return result;
}
Ejemplo n.º 9
0
INT32 nativeNfcSnep_startServer(nfcSnepServerCallback_t *serverCallback)
{
    tNFA_STATUS status = NFA_STATUS_OK;
    int ret;
    pthread_t snepRespThread;

    NXPLOG_API_D ("%s:", __FUNCTION__);
    if (serverCallback == NULL)
    {
        NXPLOG_API_E ("%s: callback is NULL!", __FUNCTION__);
        return NFA_STATUS_FAILED;
    }

    gSyncMutex.lock();
    if (!nativeNfcManager_isNfcActive())
    {
        NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__);
        gSyncMutex.unlock();
        return NFA_STATUS_FAILED;
    }

    if (sSnepServerState == SNEP_SERVER_STARTED && serverCallback == sServerCallback)
    {
        NXPLOG_API_D ("%s: alread started!", __FUNCTION__);
        gSyncMutex.unlock();
        return NFA_STATUS_OK;
    }
    if (sSnepServerState != SNEP_SERVER_IDLE)
    {
        NXPLOG_API_E ("%s: Server is started or busy. State = 0x%X", __FUNCTION__, sSnepServerState);
        gSyncMutex.unlock();
        return NFA_STATUS_FAILED;
    }

    sServerCallback = serverCallback;
    sSnepServerState = SNEP_SERVER_STARTING;

    sRfEnabled = isDiscoveryStarted();
    if (sRfEnabled)
    {
        // Stop RF Discovery if we were polling
        startRfDiscovery (FALSE);
    }
    {
        SyncEventGuard guard (sNfaSnepServerRegEvent);
        if(NFA_STATUS_OK != NFA_SnepRegisterServer(0x04, SNEP_SERVER_NAME, nfaSnepServerCallback))
        {
            status = NFA_STATUS_FAILED;
            sSnepServerState = SNEP_SERVER_IDLE;
            sServerCallback = NULL;
            goto clean_and_return;
        }
        sNfaSnepServerRegEvent.wait();
    }
    ret = pthread_create(&snepRespThread, NULL, snepServerThread, NULL);
    if(ret != 0)
    {
        NXPLOG_API_E("Unable to create snep server thread");
        sSnepServerState = SNEP_SERVER_IDLE;
        NFA_SnepDeregister(sSnepServerHandle);
        sServerCallback = NULL;
        status = NFA_STATUS_FAILED;
        goto clean_and_return;
    }

    sSnepServerState = SNEP_SERVER_STARTED;
clean_and_return:
    if (sRfEnabled)
    {
        startRfDiscovery (TRUE);
    }
    gSyncMutex.unlock();
    return status;
}
Ejemplo n.º 10
0
INT32 nativeNfcLlcp_ConnLessStartServer(nfcllcpConnlessServerCallback_t *serverCallback)
 {
    tNFA_STATUS status = NFA_STATUS_OK;
    int ret;
    pthread_t llcpRespThread;
    bServerReadState = FALSE;
    NXPLOG_API_D ("%s:", __FUNCTION__);
    if (serverCallback == NULL)
    {
        NXPLOG_API_E ("%s: callback is NULL!", __FUNCTION__);
        return NFA_STATUS_FAILED;
    }
    gSyncMutex.lock();
    if (!nativeNfcManager_isNfcActive())
    {
        NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__);
        gSyncMutex.unlock();
        return NFA_STATUS_FAILED;
    }
    if (sLlcpServerState == LLCP_SERVER_STARTED && serverCallback == sServerCallback)
    {
        NXPLOG_API_D ("%s: alread started!", __FUNCTION__);
        gSyncMutex.unlock();
        return NFA_STATUS_OK;
    }
    if (sLlcpServerState != LLCP_SERVER_IDLE)
    {
        NXPLOG_API_E ("%s: Server is started or busy. State = 0x%X", __FUNCTION__, sLlcpServerState);
        gSyncMutex.unlock();
        return NFA_STATUS_FAILED;
    }
    sServerCallback = serverCallback;
    sLlcpServerState = LLCP_SERVER_STARTING;
    sRfEnabled = isDiscoveryStarted();
    if (sRfEnabled)
    {
        /* Stop RF Discovery if we were polling */
        startRfDiscovery (FALSE);
    }
    SyncEventGuard guard (sNfaLlcpServerRegEvent);
    if(NFA_STATUS_OK != NFA_P2pRegisterServer ( LLCP_CL_SAP_ID_DEFAULT,
                                    NFA_P2P_LLINK_TYPE,
                                    (char *)LLCP_SERVER_NAME,
                                    nfaLlcpServerCallBack))
    {
        status = NFA_STATUS_FAILED;
        sLlcpServerState = LLCP_SERVER_IDLE;
        sServerCallback = NULL;
        if (sRfEnabled)
        {
            /*  Rollback to default */
            startRfDiscovery (TRUE);
            gSyncMutex.unlock();
            return status;
        }
    }
    sNfaLlcpServerRegEvent.wait();

    gSyncMutex.unlock();
    return status;


 }