static void com_android_nfc_jni_open_secure_element_notification_callback(void *pContext, phLibNfc_RemoteDevList_t *psRemoteDevList, uint8_t uNofRemoteDev, NFCSTATUS status) { struct nfc_jni_callback_data * pContextData = (struct nfc_jni_callback_data*)pContext; NFCSTATUS ret; int i; JNIEnv *e = nfc_get_env(); if(status == NFCSTATUS_DESELECTED) { LOG_CALLBACK("com_android_nfc_jni_open_secure_element_notification_callback: Target deselected", status); } else { LOG_CALLBACK("com_android_nfc_jni_open_secure_element_notification_callback", status); TRACE("Discovered %d secure elements", uNofRemoteDev); if(status == NFCSTATUS_MULTIPLE_PROTOCOLS) { bool foundHandle = false; TRACE("Multiple Protocol supported\n"); for (i=0; i<uNofRemoteDev; i++) { // Always open the phNfc_eISO14443_A_PICC protocol TRACE("Protocol %d handle=%x type=%d", i, psRemoteDevList[i].hTargetDev, psRemoteDevList[i].psRemoteDevInfo->RemDevType); if (psRemoteDevList[i].psRemoteDevInfo->RemDevType == phNfc_eISO14443_A_PICC) { secureElementHandle = psRemoteDevList[i].hTargetDev; foundHandle = true; } } if (!foundHandle) { ALOGE("Could not find ISO-DEP secure element"); status = NFCSTATUS_FAILED; goto clean_and_return; } } else { secureElementHandle = psRemoteDevList->hTargetDev; } TRACE("Secure Element Handle: 0x%08x", secureElementHandle); /* Set type name */ jintArray techList; nfc_jni_get_technology_tree(e, psRemoteDevList,uNofRemoteDev, &techList, NULL, NULL); // TODO: Should use the "connected" technology, for now use the first if ((techList != NULL) && e->GetArrayLength(techList) > 0) { e->GetIntArrayRegion(techList, 0, 1, &SecureElementTech); TRACE("Store Secure Element Info\n"); SecureElementInfo = psRemoteDevList->psRemoteDevInfo; TRACE("Discovered secure element: tech=%d", SecureElementTech); } else { ALOGE("Discovered secure element, but could not resolve tech"); status = NFCSTATUS_FAILED; } // This thread may not return to the virtual machine for a long time // so make sure to delete the local refernce to the tech list. e->DeleteLocalRef(techList); } clean_and_return: pContextData->status = status; sem_post(&pContextData->sem); }
static void com_android_nfc_jni_open_secure_element_notification_callback(void *pContext, phLibNfc_RemoteDevList_t *psRemoteDevList, uint8_t uNofRemoteDev, NFCSTATUS status) { struct nfc_jni_callback_data * pContextData = (struct nfc_jni_callback_data*)pContext; NFCSTATUS ret; int i; JNIEnv *e = nfc_get_env(); if(status == NFCSTATUS_DESELECTED) { LOG_CALLBACK("com_android_nfc_jni_open_secure_element_notification_callback: Target deselected", status); } else { LOG_CALLBACK("com_android_nfc_jni_open_secure_element_notification_callback", status); TRACE("Discovered %d tags", uNofRemoteDev); if(status == NFCSTATUS_MULTIPLE_PROTOCOLS) { TRACE("Multiple Protocol supported\n"); TRACE("Secure Element Handle: 0x%08x",psRemoteDevList[1].hTargetDev); secureElementHandle = psRemoteDevList[1].hTargetDev; /* Set type name */ jintArray techList; jintArray handleList; jintArray typeList; nfc_jni_get_technology_tree(e, psRemoteDevList,uNofRemoteDev, &techList, &handleList, &typeList); // TODO: Should use the "connected" technology, for now use the first if (e->GetArrayLength(techList) > 0) { jint* technologies = e->GetIntArrayElements(techList, 0); SecureElementTech = technologies[0]; TRACE("Store Secure Element Info\n"); SecureElementInfo = psRemoteDevList->psRemoteDevInfo; TRACE("Discovered secure element: tech=%d", SecureElementTech); } else { LOGE("Discovered secure element, but could not resolve tech"); status = NFCSTATUS_FAILED; } } else { TRACE("Secure Element Handle: 0x%08x",psRemoteDevList->hTargetDev); secureElementHandle = psRemoteDevList->hTargetDev; /* Set type name */ jintArray techList; jintArray handleList; jintArray typeList; nfc_jni_get_technology_tree(e, psRemoteDevList,uNofRemoteDev, &techList, &handleList, &typeList); // TODO: Should use the "connected" technology, for now use the first if ((techList != NULL) && e->GetArrayLength(techList) > 0) { jint* technologies = e->GetIntArrayElements(techList, 0); SecureElementTech = technologies[0]; TRACE("Store Secure Element Info\n"); SecureElementInfo = psRemoteDevList->psRemoteDevInfo; TRACE("Discovered secure element: tech=%d", SecureElementTech); } else { LOGE("Discovered secure element, but could not resolve tech"); status = NFCSTATUS_FAILED; } } } pContextData->status = status; sem_post(&pContextData->sem); }