Fix MW crash/hang observed while trying to send >32K(65K) bytes on SMB interface

 Data size check in JNI before passing to next level

Change-Id: I2d629187d4bdc11fc17d588198fc871da2bdc2b6
diff --git a/nci/SN100x/jni/NativeSecureElement.cpp b/nci/SN100x/jni/NativeSecureElement.cpp
index 53aa5b1..655b045 100755
--- a/nci/SN100x/jni/NativeSecureElement.cpp
+++ b/nci/SN100x/jni/NativeSecureElement.cpp
@@ -33,6 +33,8 @@
 
 namespace android
 {
+#define INVALID_LEN_SW1 0x64
+#define INVALID_LEN_SW2 0xFF
 static const int EE_ERROR_INIT = -3;
 extern bool nfcManager_isNfcActive();
 /*******************************************************************************
@@ -254,6 +256,15 @@
     int32_t recvBufferActualSize = 0;
     ScopedByteArrayRW bytes(e, data);
     LOG(INFO) << StringPrintf("%s: enter; handle=0x%X; buf len=%zu", __func__, handle, bytes.size());
+    if(bytes.size() > recvBufferMaxSize) {
+        LOG(ERROR) << StringPrintf("%s: datasize not supported", __func__);
+        uint8_t respBuf[] = {INVALID_LEN_SW1, INVALID_LEN_SW2};
+        jbyteArray resp = e->NewByteArray(sizeof(respBuf));
+        if (resp != NULL) {
+          e->SetByteArrayRegion(resp, 0, sizeof(respBuf), (jbyte *) respBuf);
+        }
+        return resp;
+    }
 
     SecureElement &se = SecureElement::getInstance();
     if(!se.mIsWiredModeOpen)