diff options
-rw-r--r-- | nci/jni/NativeLlcpServiceSocket.cpp | 8 | ||||
-rw-r--r-- | nci/jni/NativeLlcpSocket.cpp | 14 | ||||
-rwxr-xr-x | nci/jni/NativeNfcManager.cpp | 16 | ||||
-rwxr-xr-x | nci/jni/NativeNfcTag.cpp | 16 | ||||
-rwxr-xr-x | nci/jni/NfcTag.cpp | 30 | ||||
-rwxr-xr-x | nci/jni/NfcTag.h | 18 | ||||
-rw-r--r-- | nci/jni/PeerToPeer.cpp | 476 | ||||
-rw-r--r-- | nci/jni/PeerToPeer.h | 86 | ||||
-rwxr-xr-x | nci/jni/PowerSwitch.h | 1 | ||||
-rwxr-xr-x | nci/jni/SecureElement.cpp | 3 | ||||
-rwxr-xr-x | nci/jni/SecureElement.h | 1 | ||||
-rw-r--r-- | src/com/android/nfc/NfcDispatcher.java | 5 |
12 files changed, 148 insertions, 526 deletions
diff --git a/nci/jni/NativeLlcpServiceSocket.cpp b/nci/jni/NativeLlcpServiceSocket.cpp index ac00f61..c4a655e 100644 --- a/nci/jni/NativeLlcpServiceSocket.cpp +++ b/nci/jni/NativeLlcpServiceSocket.cpp @@ -50,13 +50,13 @@ static jobject nativeLlcpServiceSocket_doAccept(JNIEnv *e, jobject o, jint miu, jobject clientSocket = NULL; jclass clsNativeLlcpSocket = NULL; jfieldID f = 0; - tBRCM_JNI_HANDLE serverHandle; //handle of the local server + PeerToPeer::tJNI_HANDLE serverHandle; //handle of the local server bool stat = false; - tBRCM_JNI_HANDLE connHandle = PeerToPeer::getInstance().getNewJniHandle (); + PeerToPeer::tJNI_HANDLE connHandle = PeerToPeer::getInstance().getNewJniHandle (); ALOGD ("%s: enter", __FUNCTION__); - serverHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e, o); + serverHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e, o); stat = PeerToPeer::getInstance().accept (serverHandle, connHandle, miu, rw); @@ -114,7 +114,7 @@ TheEnd: static jboolean nativeLlcpServiceSocket_doClose(JNIEnv *e, jobject o) { ALOGD ("%s: enter", __FUNCTION__); - tBRCM_JNI_HANDLE jniServerHandle = 0; + PeerToPeer::tJNI_HANDLE jniServerHandle = 0; bool stat = false; jniServerHandle = nfc_jni_get_nfc_socket_handle (e, o); diff --git a/nci/jni/NativeLlcpSocket.cpp b/nci/jni/NativeLlcpSocket.cpp index 55a4a76..f5daff0 100644 --- a/nci/jni/NativeLlcpSocket.cpp +++ b/nci/jni/NativeLlcpSocket.cpp @@ -42,7 +42,7 @@ static jboolean nativeLlcpSocket_doConnect (JNIEnv* e, jobject o, jint nSap) ALOGD ("%s: enter; sap=%d", __FUNCTION__, nSap); - tBRCM_JNI_HANDLE jniHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); + PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); stat = PeerToPeer::getInstance().connectConnOriented (jniHandle, nSap); @@ -72,7 +72,7 @@ static jboolean nativeLlcpSocket_doConnectBy (JNIEnv* e, jobject o, jstring sn) bool stat = false; jboolean retVal = JNI_FALSE; - tBRCM_JNI_HANDLE jniHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); + PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); const char* serviceName = e->GetStringUTFChars (sn, JNI_FALSE); //convert jstring, which is unicode, into char* @@ -105,7 +105,7 @@ static jboolean nativeLlcpSocket_doClose(JNIEnv *e, jobject o) bool stat = false; jboolean retVal = JNI_FALSE; - tBRCM_JNI_HANDLE jniHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); + PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); stat = PeerToPeer::getInstance().disconnectConnOriented (jniHandle); @@ -134,7 +134,7 @@ static jboolean nativeLlcpSocket_doSend (JNIEnv* e, jobject o, jbyteArray data) uint32_t dataBufferLen = (uint32_t) e->GetArrayLength (data); bool stat = false; - tBRCM_JNI_HANDLE jniHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); + PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); stat = PeerToPeer::getInstance().send (jniHandle, dataBuffer, dataBufferLen); @@ -166,7 +166,7 @@ static jint nativeLlcpSocket_doReceive(JNIEnv *e, jobject o, jbyteArray origBuff bool stat = false; jint retval = 0; - tBRCM_JNI_HANDLE jniHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); + PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); stat = PeerToPeer::getInstance().receive (jniHandle, dataBuffer, dataBufferLen, actualLen); @@ -199,7 +199,7 @@ static jint nativeLlcpSocket_doGetRemoteSocketMIU (JNIEnv* e, jobject o) ALOGD ("%s: enter", __FUNCTION__); bool stat = false; - tBRCM_JNI_HANDLE jniHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); + PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); jint miu = 0; miu = PeerToPeer::getInstance().getRemoteMaxInfoUnit (jniHandle); @@ -226,7 +226,7 @@ static jint nativeLlcpSocket_doGetRemoteSocketRW (JNIEnv* e, jobject o) bool stat = false; jint rw = 0; - tBRCM_JNI_HANDLE jniHandle = (tBRCM_JNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); + PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle (e,o); rw = PeerToPeer::getInstance().getRemoteRecvWindow (jniHandle); diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp index ff61cfe..ca1bb06 100755 --- a/nci/jni/NativeNfcManager.cpp +++ b/nci/jni/NativeNfcManager.cpp @@ -42,12 +42,12 @@ extern "C" extern UINT8 *p_nfa_dm_lptd_cfg; extern UINT8 *p_nfa_dm_start_up_cfg; extern const UINT8 nfca_version_string []; -extern "C" void nfa_app_post_nci_reset (UINT32 brcm_hw_id); +extern "C" void downloadFirmwarePatchFile (UINT32 brcm_hw_id); namespace android { extern bool gIsTagDeactivating; extern bool gIsSelectingRfInterface; - extern void nativeNfcTag_doTranseiveStatus (uint8_t * buf, uint32_t buflen); + extern void nativeNfcTag_doTransceiveStatus (uint8_t * buf, uint32_t buflen); extern void nativeNfcTag_doConnectStatus (jboolean is_connect_ok); extern void nativeNfcTag_doDeactivateStatus (int status); extern void nativeNfcTag_doWriteStatus (jboolean is_write_ok); @@ -344,7 +344,7 @@ static void nfaConnectionCallback (UINT8 connEvent, tNFA_CONN_EVT_DATA* eventDat case NFA_DATA_EVT: // Data message received (for non-NDEF reads) ALOGD("%s: NFA_DATA_EVT: len = %d", __FUNCTION__, eventData->data.len); - nativeNfcTag_doTranseiveStatus(eventData->data.p_data,eventData->data.len); + nativeNfcTag_doTransceiveStatus(eventData->data.p_data,eventData->data.len); break; case NFA_SELECT_CPLT_EVT: // Select completed @@ -741,6 +741,10 @@ static jboolean nfcManager_doInitialize (JNIEnv* e, jobject o) if (!GetNumValue(NAME_NFA_DM_MULTI_TECH_RESP, &num, sizeof(num)) || (num != 0)) NFA_SetMultiTechRsp(TRUE); + // if this value exists, set polling interval. + if (GetNumValue(NAME_NFA_DM_DISC_DURATION_POLL, &num, sizeof(num))) + NFA_SetRfDiscoveryDuration(num); + // Do custom NFCA startup configuration. doStartupConfig(); goto TheEnd; @@ -940,7 +944,7 @@ static jobject nfcManager_doCreateLlcpServiceSocket (JNIEnv* e, jobject o, jint jobject serviceSocket = NULL; jclass clsNativeLlcpServiceSocket = NULL; jfieldID f = 0; - tBRCM_JNI_HANDLE jniHandle = PeerToPeer::getInstance().getNewJniHandle (); + PeerToPeer::tJNI_HANDLE jniHandle = PeerToPeer::getInstance().getNewJniHandle (); const char* serviceName = e->GetStringUTFChars (sn, JNI_FALSE); //convert jstring, which is unicode, into char* std::string serviceName2 (serviceName); @@ -1091,7 +1095,7 @@ static jobject nfcManager_doCreateLlcpSocket (JNIEnv* e, jobject o, jint nSap, j jobject clientSocket = NULL; jclass clsNativeLlcpSocket; jfieldID f; - tBRCM_JNI_HANDLE jniHandle = PeerToPeer::getInstance().getNewJniHandle (); + PeerToPeer::tJNI_HANDLE jniHandle = PeerToPeer::getInstance().getNewJniHandle (); bool stat = false; stat = PeerToPeer::getInstance().createClient (jniHandle, miu, rw); @@ -1713,7 +1717,7 @@ bool nfcManager_isNfcActive() void nfaBrcmInitCallback (UINT32 brcm_hw_id, UINT8 nvm_type) { ALOGD ("%s: enter; brcm_hw_id=0x%lX; nvm_type=0x%X", __FUNCTION__, brcm_hw_id, nvm_type); - nfa_app_post_nci_reset (brcm_hw_id); + downloadFirmwarePatchFile (brcm_hw_id); } diff --git a/nci/jni/NativeNfcTag.cpp b/nci/jni/NativeNfcTag.cpp index a4d2ec7..b4b517b 100755 --- a/nci/jni/NativeNfcTag.cpp +++ b/nci/jni/NativeNfcTag.cpp @@ -726,7 +726,7 @@ TheEnd: /******************************************************************************* ** -** Function: nativeNfcTag_doTranseiveStatus +** Function: nativeNfcTag_doTransceiveStatus ** ** Description: Receive the completion status of transceive operation. ** buf: Contains tag's response. @@ -735,7 +735,7 @@ TheEnd: ** Returns: None ** *******************************************************************************/ -void nativeNfcTag_doTranseiveStatus (uint8_t* buf, uint32_t bufLen) +void nativeNfcTag_doTransceiveStatus (uint8_t* buf, uint32_t bufLen) { ALOGD ("%s: data len=%d, waiting for transceive: %d", __FUNCTION__, bufLen, sWaitingForTransceive); if (!sWaitingForTransceive) @@ -870,6 +870,18 @@ static jbyteArray nativeNfcTag_doTransceive (JNIEnv *e, jobject o, jbyteArray da } ALOGD ("%s: response %d bytes", __FUNCTION__, sTransceiveDataLen); + + if ((natTag.getProtocol () == NFA_PROTOCOL_T2T) && + natTag.isT2tNackResponse (sTransceiveData, sTransceiveDataLen)) + { + if (targetLost) + { + ALOGD ("%s: t2t nack", __FUNCTION__); + *targetLost = 1; //causes NFC service to throw TagLostException + } + break; + } + if (sTransceiveDataLen) { // marshall data to java for return diff --git a/nci/jni/NfcTag.cpp b/nci/jni/NfcTag.cpp index 35df2f0..ed140f6 100755 --- a/nci/jni/NfcTag.cpp +++ b/nci/jni/NfcTag.cpp @@ -1165,6 +1165,36 @@ bool NfcTag::isMifareUltralight () /******************************************************************************* ** +** Function: isT2tNackResponse +** +** Description: Whether the response is a T2T NACK response. +** See NFC Digital Protocol Technical Specification (2010-11-17). +** Chapter 9 (Type 2 Tag Platform), section 9.6 (READ). +** response: buffer contains T2T response. +** responseLen: length of the response. +** +** Returns: True if the response is NACK +** +*******************************************************************************/ +bool NfcTag::isT2tNackResponse (const UINT8* response, UINT32 responseLen) +{ + static const char fn [] = "NfcTag::isT2tNackResponse"; + bool isNack = false; + + if (responseLen == 1) + { + if (response[0] == 0xA) + isNack = false; //an ACK response, so definitely not a NACK + else + isNack = true; //assume every value is a NACK + } + ALOGD ("%s: return %u", fn, isNack); + return isNack; +} + + +/******************************************************************************* +** ** Function: connectionEventHandler ** ** Description: Handle connection-related events. diff --git a/nci/jni/NfcTag.h b/nci/jni/NfcTag.h index a692ddd..276a649 100755 --- a/nci/jni/NfcTag.h +++ b/nci/jni/NfcTag.h @@ -172,10 +172,26 @@ public: *******************************************************************************/ bool isMifareUltralight (); + + /******************************************************************************* + ** + ** Function: isT2tNackResponse + ** + ** Description: Whether the response is a T2T NACK response. + ** See NFC Digital Protocol Technical Specification (2010-11-17). + ** Chapter 9 (Type 2 Tag Platform), section 9.6 (READ). + ** response: buffer contains T2T response. + ** responseLen: length of the response. + ** + ** Returns: True if the response is NACK + ** + *******************************************************************************/ + bool isT2tNackResponse (const UINT8* response, UINT32 responseLen); + private: nfc_jni_native_data* mNativeData; bool mIsActivated; - tNFC_PROTOCOL mProtocol; + tNFC_PROTOCOL mProtocol; int mtT1tMaxMessageSize; //T1T max NDEF message size tNFA_STATUS mReadCompletedStatus; tNFC_RF_TECH_PARAMS mTechParams [MAX_NUM_TECHNOLOGY]; //array of technology parameters diff --git a/nci/jni/PeerToPeer.cpp b/nci/jni/PeerToPeer.cpp index 56174d5..bf18df5 100644 --- a/nci/jni/PeerToPeer.cpp +++ b/nci/jni/PeerToPeer.cpp @@ -24,7 +24,6 @@ namespace android PeerToPeer PeerToPeer::sP2p; const std::string PeerToPeer::sSnepServiceName ("urn:nfc:sn:snep"); -const std::string PeerToPeer::sNppServiceName ("com.android.npp"); /******************************************************************************* @@ -43,13 +42,6 @@ PeerToPeer::PeerToPeer () | NFA_TECHNOLOGY_MASK_F | NFA_TECHNOLOGY_MASK_A_ACTIVE | NFA_TECHNOLOGY_MASK_F_ACTIVE), - mJniHandleSendingNppViaSnep (0), - mSnepRegHandle (NFA_HANDLE_INVALID), - mRcvFakeNppJniHandle (0), - mNppFakeOutBuffer (NULL), - mNppTotalLen (0), - mNppReadSoFar (0), - mNdefTypeHandlerHandle (NFA_HANDLE_INVALID), mNextJniHandle (1) { unsigned long num = 0; @@ -142,7 +134,7 @@ P2pServer *PeerToPeer::findServer (tNFA_HANDLE nfaP2pServerHandle) ** Returns: PeerToPeer object. ** *******************************************************************************/ -P2pServer *PeerToPeer::findServer (tBRCM_JNI_HANDLE jniHandle) +P2pServer *PeerToPeer::findServer (tJNI_HANDLE jniHandle) { for (int i = 0; i < sMax; i++) { @@ -192,7 +184,7 @@ P2pServer *PeerToPeer::findServer (const char *serviceName) ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::registerServer (tBRCM_JNI_HANDLE jniHandle, const char *serviceName) +bool PeerToPeer::registerServer (tJNI_HANDLE jniHandle, const char *serviceName) { static const char fn [] = "PeerToPeer::registerServer"; ALOGD ("%s: enter; service name: %s JNI handle: %u", fn, serviceName, jniHandle); @@ -294,7 +286,7 @@ bool PeerToPeer::registerServer (tBRCM_JNI_HANDLE jniHandle, const char *service ** Returns: None ** *******************************************************************************/ -void PeerToPeer::removeServer (tBRCM_JNI_HANDLE jniHandle) +void PeerToPeer::removeServer (tJNI_HANDLE jniHandle) { static const char fn [] = "PeerToPeer::removeServer"; @@ -338,10 +330,6 @@ void PeerToPeer::llcpActivatedHandler (nfc_jni_native_data* nat, tNFA_LLCP_ACTIV //no longer need to receive NDEF message from a tag android::nativeNfcTag_deregisterNdefTypeHandler (); - //register a type handler in case we need to send NDEF messages received from SNEP through NPP - mNdefTypeHandlerHandle = NFA_HANDLE_INVALID; - NFA_RegisterNDefTypeHandler (TRUE, NFA_TNF_DEFAULT, (UINT8 *)"", 0, ndefTypeCallback); - mRemoteWKS = activated.remote_wks; nat->vm->AttachCurrentThread (&e, NULL); @@ -442,10 +430,6 @@ void PeerToPeer::llcpDeactivatedHandler (nfc_jni_native_data* nat, tNFA_LLCP_DEA nat->vm->DetachCurrentThread (); - //PeerToPeer no longer needs to handle NDEF data event - NFA_DeregisterNDefTypeHandler (mNdefTypeHandlerHandle); - mNdefTypeHandlerHandle = NFA_HANDLE_INVALID; - //let the tag-reading code handle NDEF data event android::nativeNfcTag_registerNdefTypeHandler (); ALOGD ("%s: exit", fn); @@ -465,7 +449,7 @@ void PeerToPeer::llcpDeactivatedHandler (nfc_jni_native_data* nat, tNFA_LLCP_DEA ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::accept (tBRCM_JNI_HANDLE serverJniHandle, tBRCM_JNI_HANDLE connJniHandle, int maxInfoUnit, int recvWindow) +bool PeerToPeer::accept (tJNI_HANDLE serverJniHandle, tJNI_HANDLE connJniHandle, int maxInfoUnit, int recvWindow) { static const char fn [] = "PeerToPeer::accept"; tNFA_STATUS nfaStat = NFA_STATUS_FAILED; @@ -512,16 +496,6 @@ bool PeerToPeer::accept (tBRCM_JNI_HANDLE serverJniHandle, tBRCM_JNI_HANDLE conn serverJniHandle, connJniHandle, ii, pSrv->mServerConn[ii]->mNfaConnHandle); } - // If we had gotten a message via SNEP, fake it out to be for NPP - if (mRcvFakeNppJniHandle == serverJniHandle) - { - ALOGD ("%s: server jni handle %u diverted to NPP fake receive on conn jni handle %u", fn, serverJniHandle, connJniHandle); - delete (pSrv->mServerConn[ii]); - pSrv->mServerConn[ii] = NULL; - mRcvFakeNppJniHandle = connJniHandle; - return (true); - } - if (pSrv->mServerConn[ii]->mNfaConnHandle == NFA_HANDLE_INVALID) { delete (pSrv->mServerConn[ii]); @@ -555,7 +529,7 @@ bool PeerToPeer::accept (tBRCM_JNI_HANDLE serverJniHandle, tBRCM_JNI_HANDLE conn ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::deregisterServer (tBRCM_JNI_HANDLE jniHandle) +bool PeerToPeer::deregisterServer (tJNI_HANDLE jniHandle) { static const char fn [] = "PeerToPeer::deregisterServer"; ALOGD ("%s: enter; JNI handle: %u", fn, jniHandle); @@ -599,7 +573,7 @@ bool PeerToPeer::deregisterServer (tBRCM_JNI_HANDLE jniHandle) ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::createClient (tBRCM_JNI_HANDLE jniHandle, UINT16 miu, UINT8 rw) +bool PeerToPeer::createClient (tJNI_HANDLE jniHandle, UINT16 miu, UINT8 rw) { static const char fn [] = "PeerToPeer::createClient"; int i = 0; @@ -654,7 +628,7 @@ bool PeerToPeer::createClient (tBRCM_JNI_HANDLE jniHandle, UINT16 miu, UINT8 rw) ** Returns: None ** *******************************************************************************/ -void PeerToPeer::removeConn(tBRCM_JNI_HANDLE jniHandle) +void PeerToPeer::removeConn(tJNI_HANDLE jniHandle) { static const char fn[] = "PeerToPeer::removeConn"; int ii = 0, jj = 0; @@ -694,18 +668,7 @@ void PeerToPeer::removeConn(tBRCM_JNI_HANDLE jniHandle) } } - if (jniHandle == mRcvFakeNppJniHandle) - { - ALOGD ("%s: Reset mRcvFakeNppJniHandle: %u", fn, jniHandle); - mRcvFakeNppJniHandle = 0; - if (mNppFakeOutBuffer != NULL) - { - free (mNppFakeOutBuffer); - mNppFakeOutBuffer = NULL; - } - } - else - ALOGE ("%s: could not find handle: %u", fn, jniHandle); + ALOGE ("%s: could not find handle: %u", fn, jniHandle); } @@ -720,50 +683,10 @@ void PeerToPeer::removeConn(tBRCM_JNI_HANDLE jniHandle) ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::connectConnOriented (tBRCM_JNI_HANDLE jniHandle, const char* serviceName) +bool PeerToPeer::connectConnOriented (tJNI_HANDLE jniHandle, const char* serviceName) { static const char fn [] = "PeerToPeer::connectConnOriented"; ALOGD ("%s: enter; h: %u service name=%s", fn, jniHandle, serviceName); - - // If we are connecting to NPP and the other side supports SNEP, use SNEP - if ( (sNppServiceName.compare(serviceName)==0) && (mSnepRegHandle != NFA_HANDLE_INVALID) ) - { - P2pClient *pClient = NULL; - - if ((pClient = findClient (jniHandle)) == NULL) - { - ALOGE ("%s: can't find client, JNI handle: %u", fn, jniHandle); - return (false); - } - - if (mJniHandleSendingNppViaSnep != 0) - { - ALOGE ("%s: SNEP already active, SNEP JNI handle: %u new JNI handle: %u", fn, mJniHandleSendingNppViaSnep, jniHandle); - return (false); - } - - // Save JNI Handle and try to connect to SNEP - mJniHandleSendingNppViaSnep = jniHandle; - { - SyncEventGuard guard (pClient->mSnepEvent); - if (NFA_SnepConnect (mSnepRegHandle, const_cast<char*>("urn:nfc:sn:snep")) == NFA_STATUS_OK) - { - pClient->mSnepEvent.wait(); - - // If the connect attempt failed, connection handle is invalid - if (pClient->mSnepConnHandle != NFA_HANDLE_INVALID) - { - // return true, as if we were connected. - pClient->mClientConn.mRemoteMaxInfoUnit = 248; - pClient->mClientConn.mRemoteRecvWindow = 1; - return (true); - } - } - } - mJniHandleSendingNppViaSnep = 0; - } - - // If here, we did not establish a SNEP connection bool stat = createDataLinkConn (jniHandle, serviceName, 0); ALOGD ("%s: exit; h: %u stat: %u", fn, jniHandle, stat); return stat; @@ -781,7 +704,7 @@ bool PeerToPeer::connectConnOriented (tBRCM_JNI_HANDLE jniHandle, const char* se ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::connectConnOriented (tBRCM_JNI_HANDLE jniHandle, UINT8 destinationSap) +bool PeerToPeer::connectConnOriented (tJNI_HANDLE jniHandle, UINT8 destinationSap) { static const char fn [] = "PeerToPeer::connectConnOriented"; ALOGD ("%s: enter; h: %u dest sap: 0x%X", fn, jniHandle, destinationSap); @@ -803,7 +726,7 @@ bool PeerToPeer::connectConnOriented (tBRCM_JNI_HANDLE jniHandle, UINT8 destinat ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::createDataLinkConn (tBRCM_JNI_HANDLE jniHandle, const char* serviceName, UINT8 destinationSap) +bool PeerToPeer::createDataLinkConn (tJNI_HANDLE jniHandle, const char* serviceName, UINT8 destinationSap) { static const char fn [] = "PeerToPeer::createDataLinkConn"; ALOGD ("%s: enter", fn); @@ -886,7 +809,7 @@ P2pClient *PeerToPeer::findClient (tNFA_HANDLE nfaConnHandle) ** Returns: PeerToPeer object. ** *******************************************************************************/ -P2pClient *PeerToPeer::findClient (tBRCM_JNI_HANDLE jniHandle) +P2pClient *PeerToPeer::findClient (tJNI_HANDLE jniHandle) { for (int i = 0; i < sMax; i++) { @@ -969,7 +892,7 @@ NfaConn *PeerToPeer::findConnection (tNFA_HANDLE nfaConnHandle) ** Returns: PeerToPeer object. ** *******************************************************************************/ -NfaConn *PeerToPeer::findConnection (tBRCM_JNI_HANDLE jniHandle) +NfaConn *PeerToPeer::findConnection (tJNI_HANDLE jniHandle) { int ii = 0, jj = 0; @@ -1012,7 +935,7 @@ NfaConn *PeerToPeer::findConnection (tBRCM_JNI_HANDLE jniHandle) ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::send (tBRCM_JNI_HANDLE jniHandle, UINT8 *buffer, UINT16 bufferLen) +bool PeerToPeer::send (tJNI_HANDLE jniHandle, UINT8 *buffer, UINT16 bufferLen) { static const char fn [] = "PeerToPeer::send"; tNFA_STATUS nfaStat = NFA_STATUS_FAILED; @@ -1024,26 +947,23 @@ bool PeerToPeer::send (tBRCM_JNI_HANDLE jniHandle, UINT8 *buffer, UINT16 bufferL return (false); } - ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: send data; jniHandle: %u nfaHandle: 0x%04X mJniHandleSendingNppViaSnep: %u", - fn, pConn->mJniHandle, pConn->mNfaConnHandle, mJniHandleSendingNppViaSnep); - - // Is this a SNEP fake-out - if (jniHandle == mJniHandleSendingNppViaSnep) - { - return (sendViaSnep(jniHandle, buffer, bufferLen)); - } - - nfaStat = NFA_P2pSendData (pConn->mNfaConnHandle, bufferLen, buffer); + ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: send data; jniHandle: %u nfaHandle: 0x%04X", + fn, pConn->mJniHandle, pConn->mNfaConnHandle); - while (nfaStat == NFA_STATUS_CONGESTED) + while (true) { SyncEventGuard guard (pConn->mCongEvent); - pConn->mCongEvent.wait (); + nfaStat = NFA_P2pSendData (pConn->mNfaConnHandle, bufferLen, buffer); + if (nfaStat == NFA_STATUS_CONGESTED) + pConn->mCongEvent.wait (); //wait for NFA_P2P_CONGEST_EVT + else + break; - if (pConn->mNfaConnHandle == NFA_HANDLE_INVALID) + if (pConn->mNfaConnHandle == NFA_HANDLE_INVALID) //peer already disconnected + { + ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: peer disconnected", fn); return (false); - - nfaStat = NFA_P2pSendData (pConn->mNfaConnHandle, bufferLen, buffer); + } } if (nfaStat == NFA_STATUS_OK) @@ -1058,89 +978,6 @@ bool PeerToPeer::send (tBRCM_JNI_HANDLE jniHandle, UINT8 *buffer, UINT16 bufferL /******************************************************************************* ** -** Function: sendViaSnep -** -** Description: Send out-bound data to the stack's SNEP protocol. -** jniHandle: Handle of connection. -** buffer: Buffer of data. -** dataLen: Length of data. -** -** Returns: True if ok. -** -*******************************************************************************/ -bool PeerToPeer::sendViaSnep (tBRCM_JNI_HANDLE jniHandle, UINT8 *buffer, UINT16 dataLen) -{ - static const char fn [] = "PeerToPeer::sendViaSnep"; - tNFA_STATUS nfaStat = NFA_STATUS_FAILED; - P2pClient *pClient = NULL; - - if ((pClient = findClient (jniHandle)) == NULL) - { - ALOGE ("%s: can't find client, JNI handle: %u", fn, jniHandle); - mJniHandleSendingNppViaSnep = 0; - return (false); - } - - ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: send data; jniHandle: %u mSnepNdefMsgLen: %lu mSnepNdefBufLen: %lu dataLen: %d", - fn, jniHandle, pClient->mSnepNdefMsgLen, pClient->mSnepNdefBufLen, dataLen); - - if (pClient->mSnepNdefMsgLen == 0) - { - pClient->mSnepNdefMsgLen = (buffer[6] << 24) | (buffer[7] << 16) | (buffer[8] << 8) | buffer[9]; - if ((pClient->mSnepNdefBuf = (UINT8 *)malloc (pClient->mSnepNdefMsgLen + 1000)) == NULL) - { - ALOGE ("%s: can't malloc len: %lu", fn, pClient->mSnepNdefMsgLen); - mJniHandleSendingNppViaSnep = 0; - return (false); - } - buffer += 10; - dataLen -= 10; - } - - if ((pClient->mSnepNdefBufLen + dataLen) > pClient->mSnepNdefMsgLen) - { - ALOGE ("%s: len error mSnepNdefBufLen: %lu dataLen: %u mSnepNdefMsgLen: %lu", fn, - pClient->mSnepNdefBufLen, dataLen, pClient->mSnepNdefMsgLen); - mJniHandleSendingNppViaSnep = 0; - free (pClient->mSnepNdefBuf); - pClient->mSnepNdefBuf = NULL; - return (false); - } - - // Save the data in the buffer - memcpy (pClient->mSnepNdefBuf + pClient->mSnepNdefBufLen, buffer, dataLen); - - pClient->mSnepNdefBufLen += dataLen; - - // If we got all the data, send it via SNEP - if (pClient->mSnepNdefBufLen == pClient->mSnepNdefMsgLen) - { - ALOGD ("%s GKI_poolcount(2): %u GKI_poolfreecount(2): %u", fn, GKI_poolcount(2), GKI_poolfreecount(2)); - - SyncEventGuard guard (pClient->mSnepEvent); - nfaStat = NFA_SnepPut (pClient->mSnepConnHandle, pClient->mSnepNdefBufLen, pClient->mSnepNdefBuf); - - if (nfaStat != NFA_STATUS_OK) - { - ALOGE ("%s: NFA_SnepPut failed, code: 0x%04x", fn, nfaStat); - mJniHandleSendingNppViaSnep = 0; - free (pClient->mSnepNdefBuf); - pClient->mSnepNdefBuf = NULL; - return (false); - } - pClient->mSnepEvent.wait (); - - free (pClient->mSnepNdefBuf); - pClient->mSnepNdefBuf = NULL; - mJniHandleSendingNppViaSnep = 0; - return (pClient->mIsSnepSentOk); - } - return (true); -} - - -/******************************************************************************* -** ** Function: receive ** ** Description: Receive data from peer. @@ -1152,7 +989,7 @@ bool PeerToPeer::sendViaSnep (tBRCM_JNI_HANDLE jniHandle, UINT8 *buffer, UINT16 ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::receive (tBRCM_JNI_HANDLE jniHandle, UINT8* buffer, UINT16 bufferLen, UINT16& actualLen) +bool PeerToPeer::receive (tJNI_HANDLE jniHandle, UINT8* buffer, UINT16 bufferLen, UINT16& actualLen) { static const char fn [] = "PeerToPeer::receive"; ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: enter; jniHandle: %u bufferLen: %u", fn, jniHandle, bufferLen); @@ -1162,9 +999,6 @@ bool PeerToPeer::receive (tBRCM_JNI_HANDLE jniHandle, UINT8* buffer, UINT16 buff BOOLEAN isMoreData = TRUE; bool retVal = false; - if (jniHandle == mRcvFakeNppJniHandle) - return (feedNppFromSnep(buffer, bufferLen, actualLen)); - if ((pConn = findConnection (jniHandle)) == NULL) { ALOGE ("%s: can't find connection handle: %u", fn, jniHandle); @@ -1197,44 +1031,6 @@ bool PeerToPeer::receive (tBRCM_JNI_HANDLE jniHandle, UINT8* buffer, UINT16 buff /******************************************************************************* ** -** Function: feedNppFromSnep -** -** Description: Send incomming data to the NFC service's NDEF Push Protocol. -** buffer: Buffer of data to send. -** bufferLen: Length of data in buffer. -** actualLen: Actual length sent. -** -** Returns: True if ok. -** -*******************************************************************************/ -bool PeerToPeer::feedNppFromSnep (UINT8* buffer, UINT16 bufferLen, UINT16& actualLen) -{ - static const char fn [] = "PeerToPeer::feedNppFromSnep"; - - ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: mNppTotalLen: %lu mNppReadSoFar: %lu bufferLen: %u", - fn, mNppTotalLen, mNppReadSoFar, bufferLen); - - if (bufferLen > (mNppTotalLen - mNppReadSoFar)) - bufferLen = mNppTotalLen - mNppReadSoFar; - - memcpy (buffer, mNppFakeOutBuffer + mNppReadSoFar, bufferLen); - - mNppReadSoFar += bufferLen; - actualLen = bufferLen; - - if (mNppReadSoFar == mNppTotalLen) - { - ALOGD ("%s: entire message consumed", fn); - free (mNppFakeOutBuffer); - mNppFakeOutBuffer = NULL; - mRcvFakeNppJniHandle = 0; - } - return (true); -} - - -/******************************************************************************* -** ** Function: disconnectConnOriented ** ** Description: Disconnect a connection-oriented connection with peer. @@ -1243,7 +1039,7 @@ bool PeerToPeer::feedNppFromSnep (UINT8* buffer, UINT16 bufferLen, UINT16& actua ** Returns: True if ok. ** *******************************************************************************/ -bool PeerToPeer::disconnectConnOriented (tBRCM_JNI_HANDLE jniHandle) +bool PeerToPeer::disconnectConnOriented (tJNI_HANDLE jniHandle) { static const char fn [] = "PeerToPeer::disconnectConnOriented"; tNFA_STATUS nfaStat = NFA_STATUS_FAILED; @@ -1306,7 +1102,7 @@ bool PeerToPeer::disconnectConnOriented (tBRCM_JNI_HANDLE jniHandle) ** Returns: Peer's max information unit. ** *******************************************************************************/ -UINT16 PeerToPeer::getRemoteMaxInfoUnit (tBRCM_JNI_HANDLE jniHandle) +UINT16 PeerToPeer::getRemoteMaxInfoUnit (tJNI_HANDLE jniHandle) { static const char fn [] = "PeerToPeer::getRemoteMaxInfoUnit"; NfaConn *pConn = NULL; @@ -1331,7 +1127,7 @@ UINT16 PeerToPeer::getRemoteMaxInfoUnit (tBRCM_JNI_HANDLE jniHandle) ** Returns: Peer's receive window size. ** *******************************************************************************/ -UINT8 PeerToPeer::getRemoteRecvWindow (tBRCM_JNI_HANDLE jniHandle) +UINT8 PeerToPeer::getRemoteRecvWindow (tJNI_HANDLE jniHandle) { static const char fn [] = "PeerToPeer::getRemoteRecvWindow"; ALOGD ("%s: client jni handle: %u", fn, jniHandle); @@ -1480,15 +1276,6 @@ void PeerToPeer::handleNfcOnOff (bool isOn) } } //loop - mJniHandleSendingNppViaSnep = 0; - mRcvFakeNppJniHandle = 0; - mSnepRegHandle = NFA_HANDLE_INVALID; - - if (mNppFakeOutBuffer != NULL) - { - free (mNppFakeOutBuffer); - mNppFakeOutBuffer = NULL; - } } ALOGD ("%s: exit", fn); } @@ -1629,9 +1416,11 @@ void PeerToPeer::nfaServerCallback (tNFA_P2P_EVT p2pEvent, tNFA_P2P_EVT_DATA* ev { ALOGD ("%s: NFA_P2P_CONGEST_EVT; nfa handle: 0x%04x congested: %u", fn, eventData->congest.handle, eventData->congest.is_congested); - - SyncEventGuard guard (pConn->mCongEvent); - pConn->mCongEvent.notifyOne(); + if (eventData->congest.is_congested == FALSE) + { + SyncEventGuard guard (pConn->mCongEvent); + pConn->mCongEvent.notifyOne(); + } } break; @@ -1796,188 +1585,6 @@ void PeerToPeer::nfaClientCallback (tNFA_P2P_EVT p2pEvent, tNFA_P2P_EVT_DATA* ev /******************************************************************************* ** -** Function: snepClientCallback -** -** Description: Receive SNEP-related events from the stack. -** snepEvent: Event code. -** eventData: Event data. -** -** Returns: None -** -*******************************************************************************/ -void PeerToPeer::snepClientCallback (tNFA_SNEP_EVT snepEvent, tNFA_SNEP_EVT_DATA *eventData) -{ - static const char fn [] = "PeerToPeer::snepClientCallback"; - P2pClient *pClient; - - switch (snepEvent) - { - case NFA_SNEP_REG_EVT: - { - ALOGD ("%s NFA_SNEP_REG_EVT Status: %u Handle: 0x%X", fn, eventData->reg.status, eventData->reg.reg_handle); - SyncEventGuard guard (sP2p.mSnepRegisterEvent); - if (eventData->reg.status == NFA_STATUS_OK) - sP2p.mSnepRegHandle = eventData->reg.reg_handle; - sP2p.mSnepRegisterEvent.notifyOne (); - break; - } - - case NFA_SNEP_ACTIVATED_EVT: - ALOGD ("%s NFA_SNEP_ACTIVATED_EVT mJniHandleSendingNppViaSnep: %u", fn, sP2p.mJniHandleSendingNppViaSnep); - break; - - case NFA_SNEP_DEACTIVATED_EVT: - ALOGD ("%s NFA_SNEP_ACTIVATED_EVT mJniHandleSendingNppViaSnep: %u", fn, sP2p.mJniHandleSendingNppViaSnep); - break; - - case NFA_SNEP_CONNECTED_EVT: - if ((pClient = sP2p.findClient (sP2p.mJniHandleSendingNppViaSnep)) == NULL) - { - ALOGE ("%s: NFA_SNEP_CONNECTED_EVT - can't find SNEP client, mJniHandleSendingNppViaSnep: %u", fn, sP2p.mJniHandleSendingNppViaSnep); - } - else - { - ALOGD ("%s NFA_SNEP_CONNECTED_EVT mJniHandleSendingNppViaSnep: %u ConnHandle: 0x%04x", fn, sP2p.mJniHandleSendingNppViaSnep, eventData->connect.conn_handle); - - SyncEventGuard guard (pClient->mSnepEvent); - pClient->mSnepConnHandle = eventData->connect.conn_handle; - pClient->mSnepEvent.notifyOne(); - } - break; - - case NFA_SNEP_PUT_RESP_EVT: - if ((pClient = sP2p.findClient (sP2p.mJniHandleSendingNppViaSnep)) == NULL) - { - ALOGE ("%s: NFA_SNEP_PUT_RESP_EVT - can't find SNEP client, mJniHandleSendingNppViaSnep: %u", fn, sP2p.mJniHandleSendingNppViaSnep); - } - else - { - ALOGD ("%s NFA_SNEP_PUT_RESP_EVT mJniHandleSendingNppViaSnep: %u Result: 0x%X", fn, sP2p.mJniHandleSendingNppViaSnep, eventData->put_resp.resp_code); - - pClient->mIsSnepSentOk = (eventData->put_resp.resp_code == NFA_SNEP_RESP_CODE_SUCCESS); - - NFA_SnepDisconnect (eventData->put_resp.conn_handle, FALSE); - - SyncEventGuard guard (pClient->mSnepEvent); - pClient->mSnepEvent.notifyOne(); - } - break; - - case NFA_SNEP_DISC_EVT: - if ((pClient = sP2p.findClient (sP2p.mJniHandleSendingNppViaSnep)) == NULL) - { - ALOGE ("%s: NFA_SNEP_DISC_EVT - can't find SNEP client, mJniHandleSendingNppViaSnep: %u", fn, sP2p.mJniHandleSendingNppViaSnep); - } - else - { - ALOGD ("%s NFA_SNEP_DISC_EVT mJniHandleSendingNppViaSnep: %u", fn, sP2p.mJniHandleSendingNppViaSnep); - SyncEventGuard guard (pClient->mSnepEvent); - pClient->mSnepConnHandle = NFA_HANDLE_INVALID; - pClient->mSnepEvent.notifyOne(); - } - break; - - case NFA_SNEP_DEFAULT_SERVER_STARTED_EVT: - { - ALOGE ("%s: NFA_SNEP_DEFAULT_SERVER_STARTED_EVT", fn); - SyncEventGuard guard (sP2p.mSnepDefaultServerStartStopEvent); - sP2p.mSnepDefaultServerStartStopEvent.notifyOne(); //unblock NFA_SnepStartDefaultServer() - break; - } - - case NFA_SNEP_DEFAULT_SERVER_STOPPED_EVT: - { - ALOGE ("%s: NFA_SNEP_DEFAULT_SERVER_STOPPED_EVT", fn); - SyncEventGuard guard (sP2p.mSnepDefaultServerStartStopEvent); - sP2p.mSnepDefaultServerStartStopEvent.notifyOne(); //unblock NFA_SnepStopDefaultServer() - break; - } - break; - - default: - ALOGE ("%s UNKNOWN EVENT: 0x%04x mJniHandleSendingNppViaSnep: %u", fn, snepEvent, sP2p.mJniHandleSendingNppViaSnep); - break; - } -} - - -/******************************************************************************* -** -** Function: ndefTypeCallback -** -** Description: Receive NDEF-related events from the stack. -** ndefEvent: Event code. -** eventData: Event data. -** -** Returns: None -** -*******************************************************************************/ -void PeerToPeer::ndefTypeCallback (tNFA_NDEF_EVT ndefEvent, tNFA_NDEF_EVT_DATA *eventData) -{ - static const char fn [] = "PeerToPeer::ndefTypeCallback"; - P2pServer *pSvr = NULL; - - if (ndefEvent == NFA_NDEF_REGISTER_EVT) - { - tNFA_NDEF_REGISTER& ndef_reg = eventData->ndef_reg; - ALOGD ("%s NFA_NDEF_REGISTER_EVT Status: %u; h=0x%X", fn, ndef_reg.status, ndef_reg.ndef_type_handle); - sP2p.mNdefTypeHandlerHandle = ndef_reg.ndef_type_handle; - } - else if (ndefEvent == NFA_NDEF_DATA_EVT) - { - ALOGD ("%s NFA_NDEF_DATA_EVT Len: %lu", fn, eventData->ndef_data.len); - - if (sP2p.mRcvFakeNppJniHandle != 0) - { - ALOGE ("%s Got NDEF Data while busy, mRcvFakeNppJniHandle: %u", fn, sP2p.mRcvFakeNppJniHandle); - return; - } - - if ((pSvr = sP2p.findServer ("com.android.npp")) == NULL) - { - ALOGE ("%s Got NDEF Data but no NPP server listening", fn); - return; - } - - if ((sP2p.mNppFakeOutBuffer = (UINT8 *)malloc(eventData->ndef_data.len + 10)) == NULL) - { - ALOGE ("%s failed to malloc: %lu bytes", fn, eventData->ndef_data.len + 10); - return; - } - - sP2p.mNppFakeOutBuffer[0] = 0x01; - sP2p.mNppFakeOutBuffer[1] = 0x00; - sP2p.mNppFakeOutBuffer[2] = 0x00; - sP2p.mNppFakeOutBuffer[3] = 0x00; - sP2p.mNppFakeOutBuffer[4] = 0x01; - sP2p.mNppFakeOutBuffer[5] = 0x01; - sP2p.mNppFakeOutBuffer[6] = (UINT8)(eventData->ndef_data.len >> 24); - sP2p.mNppFakeOutBuffer[7] = (UINT8)(eventData->ndef_data.len >> 16); - sP2p.mNppFakeOutBuffer[8] = (UINT8)(eventData->ndef_data.len >> 8); - sP2p.mNppFakeOutBuffer[9] = (UINT8)(eventData->ndef_data.len); - - memcpy (&sP2p.mNppFakeOutBuffer[10], eventData->ndef_data.p_data, eventData->ndef_data.len); - - ALOGD ("%s NFA_NDEF_DATA_EVT Faking NPP on Server Handle: %u", fn, pSvr->mJniHandle); - - sP2p.mRcvFakeNppJniHandle = pSvr->mJniHandle; - sP2p.mNppTotalLen = eventData->ndef_data.len + 10; - sP2p.mNppReadSoFar = 0; - { - SyncEventGuard guard (pSvr->mConnRequestEvent); - pSvr->mConnRequestEvent.notifyOne(); - } - } - else - { - ALOGE ("%s UNKNOWN EVENT: 0x%X", fn, ndefEvent); - } - -} - - -/******************************************************************************* -** ** Function: connectionEventHandler ** ** Description: Receive events from the stack. @@ -2010,9 +1617,9 @@ void PeerToPeer::connectionEventHandler (UINT8 event, tNFA_CONN_EVT_DATA* eventD ** Returns: A new JNI handle. ** *******************************************************************************/ -tBRCM_JNI_HANDLE PeerToPeer::getNewJniHandle () +PeerToPeer::tJNI_HANDLE PeerToPeer::getNewJniHandle () { - tBRCM_JNI_HANDLE newHandle = 0; + tJNI_HANDLE newHandle = 0; mNewJniHandleMutex.lock (); newHandle = mNextJniHandle++; @@ -2082,12 +1689,7 @@ NfaConn *P2pServer::findServerConnection (tNFA_HANDLE nfaConnHandle) *******************************************************************************/ P2pClient::P2pClient () : mNfaP2pClientHandle (NFA_HANDLE_INVALID), - mIsConnecting (false), - mSnepConnHandle (NFA_HANDLE_INVALID), - mSnepNdefMsgLen (0), - mSnepNdefBufLen (0), - mSnepNdefBuf (NULL), - mIsSnepSentOk (false) + mIsConnecting (false) { } @@ -2103,8 +1705,6 @@ P2pClient::P2pClient () *******************************************************************************/ P2pClient::~P2pClient () { - if (mSnepNdefBuf) - free (mSnepNdefBuf); } diff --git a/nci/jni/PeerToPeer.h b/nci/jni/PeerToPeer.h index d689298..040ca78 100644 --- a/nci/jni/PeerToPeer.h +++ b/nci/jni/PeerToPeer.h @@ -22,7 +22,6 @@ class P2pServer; class P2pClient; class NfaConn; #define MAX_NFA_CONNS_PER_SERVER 5 -typedef unsigned int tBRCM_JNI_HANDLE; /***************************************************************************** @@ -35,6 +34,7 @@ typedef unsigned int tBRCM_JNI_HANDLE; class PeerToPeer { public: + typedef unsigned int tJNI_HANDLE; /******************************************************************************* @@ -138,7 +138,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool registerServer (tBRCM_JNI_HANDLE jniHandle, const char* serviceName); + bool registerServer (tJNI_HANDLE jniHandle, const char* serviceName); /******************************************************************************* @@ -150,7 +150,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool deregisterServer (tBRCM_JNI_HANDLE jniHandle); + bool deregisterServer (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -166,7 +166,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool accept (tBRCM_JNI_HANDLE serverJniHandle, tBRCM_JNI_HANDLE connJniHandle, int maxInfoUnit, int recvWindow); + bool accept (tJNI_HANDLE serverJniHandle, tJNI_HANDLE connJniHandle, int maxInfoUnit, int recvWindow); /******************************************************************************* @@ -181,7 +181,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool createClient (tBRCM_JNI_HANDLE jniHandle, UINT16 miu, UINT8 rw); + bool createClient (tJNI_HANDLE jniHandle, UINT16 miu, UINT8 rw); /******************************************************************************* @@ -195,7 +195,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool connectConnOriented (tBRCM_JNI_HANDLE jniHandle, const char* serviceName); + bool connectConnOriented (tJNI_HANDLE jniHandle, const char* serviceName); /******************************************************************************* @@ -209,7 +209,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool connectConnOriented (tBRCM_JNI_HANDLE jniHandle, UINT8 destinationSap); + bool connectConnOriented (tJNI_HANDLE jniHandle, UINT8 destinationSap); /******************************************************************************* @@ -224,7 +224,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool send (tBRCM_JNI_HANDLE jniHandle, UINT8* buffer, UINT16 bufferLen); + bool send (tJNI_HANDLE jniHandle, UINT8* buffer, UINT16 bufferLen); /******************************************************************************* @@ -240,7 +240,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool receive (tBRCM_JNI_HANDLE jniHandle, UINT8* buffer, UINT16 bufferLen, UINT16& actualLen); + bool receive (tJNI_HANDLE jniHandle, UINT8* buffer, UINT16 bufferLen, UINT16& actualLen); /******************************************************************************* @@ -253,7 +253,7 @@ public: ** Returns: True if ok. ** *******************************************************************************/ - bool disconnectConnOriented (tBRCM_JNI_HANDLE jniHandle); + bool disconnectConnOriented (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -266,7 +266,7 @@ public: ** Returns: Peer's max information unit. ** *******************************************************************************/ - UINT16 getRemoteMaxInfoUnit (tBRCM_JNI_HANDLE jniHandle); + UINT16 getRemoteMaxInfoUnit (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -279,7 +279,7 @@ public: ** Returns: Peer's receive window size. ** *******************************************************************************/ - UINT8 getRemoteRecvWindow (tBRCM_JNI_HANDLE jniHandle); + UINT8 getRemoteRecvWindow (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -329,7 +329,7 @@ public: ** Returns: A new JNI handle. ** *******************************************************************************/ - tBRCM_JNI_HANDLE getNewJniHandle (); + tJNI_HANDLE getNewJniHandle (); private: @@ -340,14 +340,7 @@ private: UINT16 mRemoteWKS; // Peer's well known services bool mIsP2pListening; // If P2P listening is enabled or not tNFA_TECHNOLOGY_MASK mP2pListenTechMask; // P2P Listen mask - tBRCM_JNI_HANDLE mJniHandleSendingNppViaSnep; - tNFA_HANDLE mSnepRegHandle; - tBRCM_JNI_HANDLE mRcvFakeNppJniHandle; - UINT8 *mNppFakeOutBuffer; - UINT32 mNppTotalLen; - UINT32 mNppReadSoFar; - tNFA_HANDLE mNdefTypeHandlerHandle; - tBRCM_JNI_HANDLE mNextJniHandle; + tJNI_HANDLE mNextJniHandle; P2pServer *mServers [sMax]; P2pClient *mClients [sMax]; @@ -437,7 +430,7 @@ private: ** Returns: PeerToPeer object. ** *******************************************************************************/ - P2pServer *findServer (tBRCM_JNI_HANDLE jniHandle); + P2pServer *findServer (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -463,7 +456,7 @@ private: ** Returns: None ** *******************************************************************************/ - void removeServer (tBRCM_JNI_HANDLE jniHandle); + void removeServer (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -476,7 +469,7 @@ private: ** Returns: None ** *******************************************************************************/ - void removeConn (tBRCM_JNI_HANDLE jniHandle); + void removeConn (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -491,7 +484,7 @@ private: ** Returns: True if ok. ** *******************************************************************************/ - bool createDataLinkConn (tBRCM_JNI_HANDLE jniHandle, const char* serviceName, UINT8 destinationSap); + bool createDataLinkConn (tJNI_HANDLE jniHandle, const char* serviceName, UINT8 destinationSap); /******************************************************************************* @@ -517,7 +510,7 @@ private: ** Returns: PeerToPeer object. ** *******************************************************************************/ - P2pClient *findClient (tBRCM_JNI_HANDLE jniHandle); + P2pClient *findClient (tJNI_HANDLE jniHandle); /******************************************************************************* @@ -556,37 +549,7 @@ private: ** Returns: PeerToPeer object. ** *******************************************************************************/ - NfaConn *findConnection (tBRCM_JNI_HANDLE jniHandle); - - - /******************************************************************************* - ** - ** Function: sendViaSnep - ** - ** Description: Send out-bound data to the stack's SNEP protocol. - ** jniHandle: Handle of connection. - ** buffer: Buffer of data. - ** dataLen: Length of data. - ** - ** Returns: True if ok. - ** - *******************************************************************************/ - bool sendViaSnep (tBRCM_JNI_HANDLE jniHandle, UINT8 *buffer, UINT16 bufferLen); - - - /******************************************************************************* - ** - ** Function: feedNppFromSnep - ** - ** Description: Send incomming data to the NFC service's NDEF Push Protocol. - ** buffer: Buffer of data to send. - ** bufferLen: Length of data in buffer. - ** actualLen: Actual length sent. - ** - ** Returns: True if ok. - ** - *******************************************************************************/ - bool feedNppFromSnep (UINT8* buffer, UINT16 bufferLen, UINT16& actualLen); + NfaConn *findConnection (tJNI_HANDLE jniHandle); }; @@ -601,7 +564,7 @@ class NfaConn { public: tNFA_HANDLE mNfaConnHandle; // NFA handle of the P2P connection - tBRCM_JNI_HANDLE mJniHandle; // JNI handle of the P2P connection + PeerToPeer::tJNI_HANDLE mJniHandle; // JNI handle of the P2P connection UINT16 mMaxInfoUnit; UINT8 mRecvWindow; UINT16 mRemoteMaxInfoUnit; @@ -635,7 +598,7 @@ class P2pServer { public: tNFA_HANDLE mNfaP2pServerHandle; // NFA p2p handle of local server - tBRCM_JNI_HANDLE mJniHandle; // JNI Handle + PeerToPeer::tJNI_HANDLE mJniHandle; // JNI Handle SyncEvent mRegServerEvent; // for NFA_P2pRegisterServer() SyncEvent mConnRequestEvent; // for accept() std::string mServiceName; @@ -679,11 +642,6 @@ class P2pClient public: tNFA_HANDLE mNfaP2pClientHandle; // NFA p2p handle of client bool mIsConnecting; // Set true while connecting - tNFA_HANDLE mSnepConnHandle; - UINT32 mSnepNdefMsgLen; // SNEP total NDEF message length - UINT32 mSnepNdefBufLen; // SNEP NDEF buffer length - UINT8 *mSnepNdefBuf; // SNEP NDEF Message - bool mIsSnepSentOk; // SNEP transmission status NfaConn mClientConn; SyncEvent mRegisteringEvent; // For client registration SyncEvent mConnectingEvent; // for NFA_P2pConnectByName or Sap() diff --git a/nci/jni/PowerSwitch.h b/nci/jni/PowerSwitch.h index 896133e..2e6b604 100755 --- a/nci/jni/PowerSwitch.h +++ b/nci/jni/PowerSwitch.h @@ -10,7 +10,6 @@ *****************************************************************************/ #pragma once #include "nfa_api.h" -#include "nfa_brcm_api.h" #include "SyncEvent.h" diff --git a/nci/jni/SecureElement.cpp b/nci/jni/SecureElement.cpp index 1d52955..e4d9400 100755 --- a/nci/jni/SecureElement.cpp +++ b/nci/jni/SecureElement.cpp @@ -17,6 +17,7 @@ #include "PowerSwitch.h" #include "HostAidRouter.h" #include "nfa_vs_brcm_api.h" +#include "nfa_brcm_api.h" #include "JavaClassConstants.h" @@ -183,7 +184,7 @@ bool SecureElement::initialize (nfc_jni_native_data* native) SyncEventGuard guard (mHciRegisterEvent); - nfaStat = NFA_HciRegister (const_cast<char*>("brcm_jni"), nfaHciCallback, TRUE); + nfaStat = NFA_HciRegister (const_cast<char*>("nfc_jni"), nfaHciCallback, TRUE); if (nfaStat != NFA_STATUS_OK) { ALOGE ("%s: fail hci register; error=0x%X", fn, nfaStat); diff --git a/nci/jni/SecureElement.h b/nci/jni/SecureElement.h index ea1f568..65e779e 100755 --- a/nci/jni/SecureElement.h +++ b/nci/jni/SecureElement.h @@ -16,7 +16,6 @@ #include "RouteDataSet.h" extern "C" { - #include "nfa_brcm_api.h" #include "nfa_ee_api.h" #include "nfa_hci_api.h" #include "nfa_hci_defs.h" diff --git a/src/com/android/nfc/NfcDispatcher.java b/src/com/android/nfc/NfcDispatcher.java index b3ab97c..f628dea 100644 --- a/src/com/android/nfc/NfcDispatcher.java +++ b/src/com/android/nfc/NfcDispatcher.java @@ -305,7 +305,10 @@ public class NfcDispatcher { if (message == null) { return false; } - dispatch.setNdefIntent(); + Intent intent = dispatch.setNdefIntent(); + + // Bail out if the intent does not contain filterable NDEF data + if (intent == null) return false; // Try to start AAR activity with matching filter List<String> aarPackages = extractAarPackages(message); |