static jbyteArray com_android_nfc_NativeNfcSecureElement_doTransceive(JNIEnv *e, jobject o, jint handle, jbyteArray data)
{
	jbyteArray result = NULL;
	uint8_t* pSendApduBuffer;
	uint32_t nSendApduBufferLength;
	uint8_t receivedApduBuffer[RECEIVE_APDU_BUFFER_MAX_LENGTH];
	uint32_t nReceivedApduActualLength;

	LogInformation("NativeNfcSecureElement.doTransceive() with handle %d", handle);

	pSendApduBuffer = (uint8_t *) e->GetByteArrayElements(data, NULL);
	nSendApduBufferLength = (uint32_t) e->GetArrayLength(data);

	W_ERROR error = W7816ExchangeAPDUSync((W_HANDLE) handle, pSendApduBuffer, nSendApduBufferLength, receivedApduBuffer,
			RECEIVE_APDU_BUFFER_MAX_LENGTH, &nReceivedApduActualLength);

	if (error != W_SUCCESS)
	{
		LogError("NativeNfcSecureElement.doTransceive(): exchange APDU failed: error=0x%X",
				error);
	} else
	{
	/* Copy results back to Java */
		LogInformation("NativeNfcSecureElement.doTransceive(): received APDU reply - %d bytes", nReceivedApduActualLength);
		result = e->NewByteArray(nReceivedApduActualLength);
	   if(result != NULL)
	   {
		  e->SetByteArrayRegion(result, 0, nReceivedApduActualLength, (jbyte *) receivedApduBuffer);
	   }
	}

	e->ReleaseByteArrayElements(data, (jbyte*) pSendApduBuffer, JNI_ABORT);

   return result;
}
static jint com_android_nfc_NativeNfcSecureElement_doOpenSecureElementConnection(JNIEnv *e, jobject o)
{
	LogInformation("NativeNfcSecureElement.doOpenSecureElementConnection()");
	W_HANDLE hChannel = 0;
	W_ERROR error = -1;
	if (seInitialized == W_FALSE)
	{
		getSecureElementList();
		seInitialized = W_TRUE;
	}
	if (defaultSEId != UNDEFINED)
	{
		error = WSEOpenConnectionSync(defaultSEId, W_TRUE, &seConnection);
		LogInformation("NativeNfcSecureElement.doOpenSecureElementConnection(): opened connection to SE: handle=%d", seConnection);
		if (error == W_SUCCESS)
		{
			error = W7816OpenChannelSync(seConnection, W_7816_CHANNEL_TYPE_RAW, NULL, 0, &hChannel);
			if (error != W_SUCCESS)
			{
				LogError("NativeNfcSecureElement.doOpenSecureElementConnection(): can't open Channel to SE: error=0x%X", error);
			}
		}else
		{
			LogError("NativeNfcSecureElement.doOpenSecureElementConnection(): can't open connection to SE: error=0x%X", error);
		}
	}
	else
	{
		LogWarning("NativeNfcSecureElement.doOpenSecureElementConnection(): default Secure Element is not set");
	}

	LogInformation("openSecureElementConnection - returned hChannel: %d", hChannel);
	return (jint) hChannel;
}
static jint com_opennfc_extension_engine_VirtualTagAdapter_virtualTagCreate(JNIEnv * e, jobject o, jint cardType, jbyteArray identifier,
		jint tagCapacity, jint virtualTagIndice)
{
	LogInformation(" Jni virtualTagCreate");
	W_HANDLE phHandle = 0;
	uint8_t vtIndice;
	uint8_t type;
	uint32_t maxLength;
	JNIEnv env = *e;
	vtIndice = virtualTagIndice;
	type = cardType;
	maxLength = tagCapacity;

	uint8_t * uid = (uint8_t *) env->GetByteArrayElements(e, identifier, NULL);
	uint32_t uidLen = (uint32_t) env->GetArrayLength(e, identifier);

	if (type == 2) // W_PROP_ISO_14443_4_A
	{
		type = W_PROP_NFC_TAG_TYPE_4_A;
	}
	else if (type == 4)
	{ // W_PROP_ISO_14443_4_B
		type = W_PROP_NFC_TAG_TYPE_4_B;
	}

	WVirtualTagCreate(type, uid, uidLen, maxLength, &phHandle);

	env->ReleaseByteArrayElements(e, identifier, (jbyte *) uid, JNI_ABORT);
	LogInformation("virtualTagCreate jni: handle = %d", phHandle);
	return (jint) phHandle;
}
static void com_opennfc_extension_nfc_api_OpenNFCExtManager_nativeSendData(JNIEnv * e, jobject o, jint extClientId, jbyte cmd, jint reqId, jbyteArray data)
{
    JNIEnv env = *e;
    bool_t status;
    tMessageOpenNFC msg;

    LogInformation("nativeSendData(): ENTER");
    msg.header.clientId = extClientId;
    msg.header.commandId = cmd;
    msg.header.reqId = reqId;
    msg.pData = (uint8_t*) env->GetByteArrayElements(e, data, NULL);
    msg.header.length  = (msg.pData == NULL) ? 0 : env->GetArrayLength(e, data);

    LogInformation("nativeSendData: length=%d, pData=%p", msg.header.length, msg.pData);
    status = sendOpenNfcExtMessage(&msg);

    env->ReleaseIntArrayElements(e, data, (jint*) msg.pData, 0);

    /*
    	pthread_t openNfcExtRcvNotificationsThreadId;
    	pthread_create(&openNfcExtRcvNotificationsThreadId, NULL, testThread, (void*) o);
    */

//	   f = e->GetFieldID(c, "mConnectedTechIndex", "I");

}
/*	callback function to be called when the notification is received */
static void openNfcExtNotifCallback (tMessageOpenNFC* pMessage)
{
	LogInformation("openNfcExtNotifCallback: ENTER");

	char* dump = dumpUnit8Array(pMessage->pData,  pMessage->length);
	LogInformation("openNfcExtNotifCallback: Message: length = %d, data=%s",
			pMessage->length, dump);
	free (dump);
	LogInformation("openNfcExtNotifCallback: EXIT");
}
W_ERROR getSecureElementList()
{
	LogInformation("getSecureElementList");

	W_ERROR nError;
	if ((nError = WNFCControllerGetIntegerProperty(W_NFCC_PROP_SE_NUMBER, &seNumber)) == W_SUCCESS)
	{
		LogInformation("getSecureElementList(): seNumber=%d", seNumber);

	} else
	{
		LogError("Can't get Secure Elements number (err=0x%X)", nError);
		return nError;
	}
	if (seNumber > MAX_SE_NUMBER)
	{
		LogWarning("Too many Secure Elements (%d), retrieve only %d", seNumber, MAX_SE_NUMBER);
		seNumber = MAX_SE_NUMBER;
	}
	for(uint32_t index = 0; index < seNumber; index++)
	{
		W_ERROR seError;
		if ((seError = WSEGetInfoEx(index, &seInfo[index])) != W_SUCCESS)
		{
			nError = seError;
			break;
		} else {
			tWSEInfoEx* pInfo = &seInfo[index];
			LogInformation("getSecureElementList(): SE #%d: protocols=0x%X, capabilities=0x%X",
					pInfo->nSlotIdentifier,
					pInfo->nSupportedProtocols, pInfo->nCapabilities);
			if ((pInfo->nCapabilities & W_SE_FLAG_COMMUNICATION) && (defaultSEId == UNDEFINED))
			{
				defaultSEId = index;
				LogInformation("getSecureElementList(): defaultSEId=%d, capabilities=0x%X", index,
						pInfo->nCapabilities);
			}
			if ((pInfo->nCapabilities & W_SE_FLAG_UICC) && (uiccId == UNDEFINED))
			{
				uiccId = index;
				LogInformation("getSecureElementList(): uiccId=%d, capabilities=0x%X", index,
						pInfo->nCapabilities);
			}
		}
	}

	if (defaultSEId == UNDEFINED)
	{
		LogWarning("Default Secure Element can't be selected");
	}
	return nError;
}
/*	callback function to be called when the notification for Open NFC Extension Manager's reply is received */
void openNfcExtNotifCallback (tMessageOpenNFC* pMessage)
{
    LogInformation("openNfcExtNotifCallback: ENTER");

    JNIEnv* e = getJniEnv();
    jmethodID method;
    JNIEnv env = *e;
    jbyteArray outData = env->NewByteArray(e, pMessage->header.length);
    if (pMessage->header.length > 0) {
        env->SetByteArrayRegion(e, outData, 0, pMessage->header.length,
                                (jbyte *) pMessage->pData);
    }

    method = env->GetStaticMethodID(e, classManager, "replyCallback", "(II[B)V");
    if (method == 0) {
        LogError("openNfcExtNotifCallback(): can't call replyCallback()");
        return;
    }

    env->CallStaticVoidMethod(e, classManager, method, pMessage->header.reqId, pMessage->header.errStatus,
                              outData);
    env->DeleteLocalRef(e, outData);
    freeJniEnv();

}
void pEventCallback(void *pHandlerParameter, uint32_t nEventCode)
{
	LogInformation(" Jni pEventCallback");
	int indice;
	indice = (int *) pHandlerParameter;
	cardEmulationEventCallback(indice, nEventCode);
}
void pCommandCallback(void *pCallbackParameter, uint32_t nDataLength)
{
	LogInformation(" Jni pCommandCallback");
	int indice;
	indice = (int *) pCallbackParameter;
	cardEmulationCommandEventCallback(indice);
}
void vEventCallback(void *pHandlerParameter, uint32_t nEventCode)
{
	LogInformation(" Jni virtualTag: vEventCallback");
	int indice;
	indice = (int *) pHandlerParameter;
	virtualTagEventCallback(indice, nEventCode);
}
Example #11
0
DevId_t DmCreateDevice(char *Name, MCoreDevice_t *Device)
{
	/* Grap lock */
	SpinlockAcquire(&GlbDmLock);
	
	/* Set name and data */
	Device->Name = strdup(Name);
	Device->Id = GlbDmIdentfier;

	/* Increase */
	GlbDmIdentfier++;

	/* Release */
	SpinlockRelease(&GlbDmLock);

	/* Add to list */
	list_append(GlbDmDeviceList, list_create_node(Device->Id, (void*)Device));

	/* Call some broadcast function so systems know a new device is avaiable
	 * depending on the device type */
	switch (Device->Type)
	{
		/* Give access to timer */
		case DeviceTimer:
		{
			/* Cast */
			MCoreTimerDevice_t *Timer = (MCoreTimerDevice_t*)Device->Data;
			Timer->ReportMs = TimersApplyMs;

		} break;

		/* Give access to input */
		case DeviceInput:
		{
			/* Cast */
			MCoreInputDevice_t *Input = (MCoreInputDevice_t*)Device->Data;
			Input->ReportEvent = EmCreateEvent;

		} break;

		/* Register with Vfs */
		case DeviceStorage:
		{
			/* Call */
			VfsRegisterDisk(Device->Id);

		} break;

		/* No special actions */
		default:
			break;
	}

	/* Info Log */
	LogInformation("DRVM", "New Device: %s", Name);

	/* Done */
	return Device->Id;
}
/*	callback function to be called when cardEmulation Command happens */
void cardEmulationCommandEventCallback(int indice)
{
	LogInformation("cardEmulationCommandEventCallback: ENTER");
	JNIEnv* e = attachJniEnv();
	jmethodID method;
	JNIEnv env = *e;
	jbyteArray returnData = NULL;

	method = env->GetMethodID(e, classManager, "getCardEmulationHandle", "(I)I");
	if (method == 0)
	{
		LogError("getCardEmulationHandle(): can't call getCardEmulationHandle()");
		detachJniEnv();
		return;
	}
	jint handle = (jint) env->CallIntMethod(e, job, method, indice);

	LogInformation(" getCommandData: indice = %d   handle = %d", indice, handle);
	uint8_t * pDataBuffer = (uint8_t*) malloc(RETURN_MESSAGE_MAX_BUFFER_SIZE);
	if (pDataBuffer != null)
	{
	uint32_t pnActualDataLength = 0;
	WEmulGetMessageData((W_HANDLE) handle, pDataBuffer, TRANSCEIVE_MAX_BUFFER_SIZE, &pnActualDataLength);

	returnData = env->NewByteArray(e, pnActualDataLength);
	if (returnData != NULL)
	{
		env->SetByteArrayRegion(e, returnData, 0, pnActualDataLength, (jbyte *) pDataBuffer);
	}

	method = env->GetMethodID(e, classManager, "cardEmulCommandCallback", "(I[B)V");
	if (method == 0)
	{
		LogError("cardEmulationEventCallback(): can't call cardEmulEventCallback()");
		free(pDataBuffer);
		env->DeleteLocalRef(e, returnData);
		detachJniEnv();
		return;
	}
	env->CallVoidMethod(e, job, method, indice, returnData);
	free(pDataBuffer);
	}
	env->DeleteLocalRef(e, returnData);
	detachJniEnv();
}
Example #13
0
int semaphore_init(sem_t * semaphore, const char * file, int line)
{
	int status;
	LogInformation("Initialization of semaphore in %s at %d", file, line);
	if ((status = sem_init(semaphore, 0, 0)) == -1)
	{
		LogError("sem_init() failed in %s at %d (errno=0x%X)", file, line, errno);
	}
	return status;
}
/**
 * Launch the test framework
 * @param	nArgc	Number of arguments
 * @param	pArgv	Arguments give
 */
int main(int nArgc, char* pArgv[])
{
	int resultStart;
	bool_t status;
	uint8_t data[] = {0x01, 0x02};
	tMessageOpenNFC msg;

	msg.length = 2;
	msg.pData = &data;
	msg.clientId = OPEN_NFC_TEST;
	LogInformation("\n*****************************\n\t Starting Open NFC Wrapper Test Launcher !\n");

	registerOpenNfcExtNotificationCallback(OPEN_NFC_TEST, openNfcExtNotifCallback);

	status = openOpenNfcExtConnection();
	LogInformation("called openOpenNfcExtConnection(): status = %d", status);
	sleep(3);

	char* dump = dumpUnit8Array(msg.pData,  msg.length);
	LogInformation( "Message: length = %d, data=%s", msg.length, dump);
	free (dump);

	status = sendOpenNfcExtMessage(&msg);
	LogInformation("called sendOpenNfcExtMessage(): status = %d", status);

	sleep(300);
	status = closeOpenNfcExtConnection();
	LogInformation("called closeOpenNfcExtConnection(): status = %d", status);

/*
	if(nArgc<3)
	{
		LogError("Not enough parameter !");
		LogError("Usage : %s <TARGET> <CONFIGURATION>", pArgv[0]);
		LogError("     <TARGET>        : Target to reach, use M for Microread and S for Simulator");
		LogError("     <CONFIGURATION> : Configuration (IP)");

		return -1;
	}
*/

	return 0;
}
static jint com_opennfc_extension_engine_CardEmulationAdapter_sendAnswer(JNIEnv * e, jobject o, jint handle, jbyteArray reponse)
{
	uint32_t result = -1;
	LogInformation("Jni: sendAnswer ");
	JNIEnv env = *e;
	uint8_t * rps = (uint8_t *) env->GetByteArrayElements(e, reponse, NULL);
	uint32_t rpsLen = (uint32_t) env->GetArrayLength(e, reponse);
	result = WEmulSendAnswer((W_HANDLE) handle, rps, rpsLen);
	env->ReleaseByteArrayElements(e, reponse, (jbyte *) rps, JNI_ABORT);
	return (jint) result;
}
Example #16
0
/* Initialize Vfs */
void VfsInit(void)
{
	/* Debug */
	LogInformation("VFSM", "Initializing");

	/* Create lists */
	GlbFileSystems = list_create(LIST_SAFE);
	GlbOpenFiles = list_create(LIST_SAFE);
	GlbFileSystemId = 0;
	GlbVfsInitHasRun = 0;
}
Example #17
0
int semaphore_destroy(sem_t * semaphore, const char * file, int line)
{
	int status;
	LogInformation("Close semaphore in %s at %d", file, line);

	if ((status = sem_destroy(semaphore)) == -1)
	{
		LogError("sem_destroy() failed in %s at %d (errno=0x%X)", file, line, errno);
	}
	return status;
}
static jint com_opennfc_extension_engine_SecureElementAdapter_getSecureElementsNumber(JNIEnv * e, jobject o)
{
	int nbSE = 0;
	W_ERROR error = WNFCControllerGetIntegerProperty(W_NFCC_PROP_SE_NUMBER, &nbSE);
	LogInformation("getSecureElements(): SE number = %d", nbSE);

	if (error != W_SUCCESS)
	{
		LogError("Can't retrieve the number of Secure Elements (error=0x%X)", error);
	}
	return (jint) nbSE;
}
static jboolean com_opennfc_extension_engine_CardEmulationAdapter_setCardEmulationMode(JNIEnv * e, jobject o, jboolean enable)
{
	W_ERROR error;
	if (enable == JNI_TRUE)
	{
		WNFCControllerGetRFLock(W_NFCC_STORAGE_VOLATILE, &readerLock, &cardLock);
		LogInformation("start CardEmulation Mode with readerLock %d cardLock %d", readerLock, cardLock);
		error = WNFCControllerSetRFLockSync(W_NFCC_STORAGE_VOLATILE, W_TRUE, W_FALSE);
		error = WNFCControllerSwitchStandbyMode(W_FALSE);
	}
	else
	{
		error = WNFCControllerSetRFLockSync(W_NFCC_STORAGE_VOLATILE, readerLock, cardLock);
		LogInformation("shut down CardEmulation mode with readerLock %d", readerLock);
		LogInformation("shut down CardEmulation mode with cardLock %d", cardLock);
		error = WNFCControllerSwitchStandbyMode(W_TRUE);
	}
	if (error == W_SUCCESS)
		return JNI_TRUE;

	return JNI_FALSE;
}
Example #20
0
/* Register fs */
void VfsInstallFileSystem(MCoreFileSystem_t *Fs)
{
	/* Ready the buffer */
	char IdentBuffer[8];
	memset(IdentBuffer, 0, 8);

	/* Copy the storage ident over */
	strcpy(IdentBuffer, "St");
	itoa(GlbFileSystemId, (IdentBuffer + 2), 10);

	/* Construct the identifier */
	Fs->Identifier = MStringCreate(&IdentBuffer, StrASCII);

	/* Setup last */
	Fs->Lock = MutexCreate();

	/* Add to list */
	list_append(GlbFileSystems, list_create_node(Fs->DiskId, Fs));

	/* Increament */
	GlbFileSystemId++;

	/* Start init? */
	if (Fs->Flags & VFS_MAIN_DRIVE
		&& !GlbVfsInitHasRun)
	{
		/* Process Request */
		MCoreProcessRequest_t *ProcRequest
			= (MCoreProcessRequest_t*)kmalloc(sizeof(MCoreProcessRequest_t));

		/* Print */
		LogInformation("VFSM", "Boot Drive Detected, Running Init");

		/* Append init path */
		MString_t *Path = MStringCreate(Fs->Identifier->Data, StrUTF8);
		MStringAppendChars(Path, FILESYSTEM_INIT);

		/* Create Request */
		ProcRequest->Type = ProcessSpawn;
		ProcRequest->Path = Path;
		ProcRequest->Arguments = NULL;
		ProcRequest->Cleanup = 1;

		/* Send */
		PmCreateRequest(ProcRequest);

		/* Set */
		GlbVfsInitHasRun = 1;
	}
}
static jboolean com_opennfc_extension_engine_VirtualTagAdapter_writeNdefMessage(JNIEnv * e, jobject o, jbyteArray buf,
		jint virtualTagHandle)
{
	JNIEnv env = *e;
	W_HANDLE msg_handle;
	W_ERROR result = W_ERROR_TAG_WRITE;

	uint32_t ndefMessageLength = (uint32_t) env->GetArrayLength(e, buf);
	if (ndefMessageLength == 0)
		{
			LogError("VirtualTagAdapter_writeNdefMessage: Nothing to write");
			return JNI_FALSE;
		}

	uint8_t *buffer = (uint8_t *) env->GetByteArrayElements(e, buf, NULL);
	LogInformation("do writeNdefMessage");
	WNDEFBuildMessage(buffer, ndefMessageLength, &msg_handle);


	result = WNDEFWriteMessageSync(virtualTagHandle, msg_handle, W_NDEF_ACTION_BIT_FORMAT_NON_NDEF_TAG | W_NDEF_ACTION_BIT_ERASE);
	LogInformation("VirtualTagAdapter_writeNdefMessage OK with result = %d", result);
	env->ReleaseByteArrayElements(e, buf, (jbyte *) buffer, JNI_ABORT);
	return (result == W_SUCCESS ? JNI_TRUE : JNI_FALSE);
}
Example #22
0
/* Starts the DeviceManager request thread */
void DmStart(void)
{
	/* Debug */
	LogInformation("DRVM", "Starting Request Handler");

	/* Create the signal & Request queue */
	GlbDmEventLock = SemaphoreCreate(0);
	GlbDmEventQueue = list_create(LIST_SAFE);

	/* Spawn the thread */
	ThreadingCreateThread("Device Event Thread", DmRequestHandler, NULL, 0);

	/* Is there a boot video? */
	if (GlbDmBootVideo != NULL)
		DmCreateDevice("Boot-Video", GlbDmBootVideo);
}
static jboolean com_android_nfc_NativeNfcSecureElement_doDisconnect(JNIEnv *e, jobject o, jint handle)
{
	LogInformation("NativeNfcSecureElement.doDisconnect()");
	jboolean status = JNI_TRUE;
	// Close SE RAW channel handle
	W_ERROR error = WBasicCloseHandleSafeSync((W_HANDLE) handle);
	// Close SE connection handle, only one SE connected for the current version
	error = WBasicCloseHandleSafeSync((W_HANDLE) seConnection);

	if (error != W_SUCCESS)
	{
		LogError("NativeNfcSecureElement.doDisconnect(): can't close SE connection handle: error=0x%X",
				error);
		status = JNI_FALSE;
	}
	return status;
}
/*	callback function to be called when virtualTag Event happens */
void virtualTagEventCallback(int indice, int event)
{
	LogInformation("virtualTagEventCallback: ENTER");

	JNIEnv* e = attachJniEnv();
	jmethodID method;
	JNIEnv env = *e;
	method = env->GetMethodID(e, classManager, "virtualTagEventCallback", "(II)V");
	if (method == 0)
	{
		LogError("virtualTagEventCallback(): can't call virtualTagEventCallback()");
		detachJniEnv();
		return;
	}
	env->CallVoidMethod(e, job, method, indice, event);
	detachJniEnv();
}
static jintArray com_android_nfc_NativeNfcSecureElement_doGetTechList(JNIEnv *e, jobject o, jint handle)
{
	LogInformation("NativeNfcSecureElement.doGetTechList");
	jintArray techList;
	/*
		if(handle <= (jint) seNumber)
		{
			techList = e->NewIntArray(1);
			e->SetIntArrayRegion(techList, 0, 1, &SecureElementTech);
			return techList;
		}
		else
		{
			LogWarning("NativeNfcSecureElement.doGetUid(): invalid handle=%d", handle);
			return NULL;
		}
	*/
	LogWarning("NativeNfcSecureElement.doGetTechList(): handle=%d", handle);
    return NULL;
}
static jbyteArray com_android_nfc_NativeNfcSecureElement_doGetUid(JNIEnv *e, jobject o, jint handle)
{
	LogInformation("NativeNfcSecureElement.doGetUid()");
	jbyteArray SecureElementUid;

/*
	if(handle <= (jint) seNumber)
	{
	  SecureElementUid = e->NewByteArray(SecureElementInfo->RemoteDevInfo.Iso14443A_Info.UidLength);
	  e->SetByteArrayRegion(SecureElementUid, 0, SecureElementInfo->RemoteDevInfo.Iso14443A_Info.UidLength,(jbyte *)SecureElementInfo->RemoteDevInfo.Iso14443A_Info.Uid);
	  return SecureElementUid;
	}
	else
	{
		LogWarning("NativeNfcSecureElement.doGetUid(): invalid handle=%d", handle);
		return NULL;
	}
*/
	LogWarning("NativeNfcSecureElement.doGetUid(): handle=%d", handle);
	return NULL;
}
Example #27
0
void main()
{
    /* Declare the variables to be used */
    int i,j,tempchar;
    int results[5][100];
    char logString[100];

    for(i=0;i<5;i++) {
        for(j=0;j<100;j++) {
            results[i][j]=0;
        }
    }
    
    clrscreen();
    for(j=0;j<100;j++) {
        printf("Answer %d:",j + 1);
        while ((tempchar < 97) || (tempchar > 101)) {
        	tempchar=getch();
        	if (tempchar = 8) {
        		return;
        	}
        }
        results[tempchar - 97][j]++;
        clrscreen();
    }
    
    for(j=0;j<100;j++) {
        strcpy(logString,"");
        sprintf(logString,"A: %d",results[0][j]);
        sprintf(logString,"%s|B: %d",logString,results[1][j]);
        sprintf(logString,"%s|C: %d",logString,results[2][j]);
        sprintf(logString,"%s|D: %d",logString,results[3][j]);
        sprintf(logString,"%s|E: %d\n",logString,results[4][j]);
        printf("%s",logString);
        LogInformation(logString);
    }
} // End of main()
bool_t getCardLock(){
	LogInformation("shut down Virtual Tag mode with cardLock %d", cardLock);
	return cardLock;
}
static jbyteArray com_opennfc_extension_engine_VirtualTagAdapter_readNdefMessage(JNIEnv * e, jobject o, jint ndefType,
		jint virtualTagHandle)
{
	JNIEnv env = *e;
	jbyteArray result = NULL;
	uint32_t messageLength;
	W_HANDLE hMessage;

	WNDEFReadMessageSync(virtualTagHandle, (uint8_t) ndefType, null, &hMessage);
	if (hMessage == W_NULL_HANDLE)
	{
		LogError("hMessage is null, readNdefMessage returns null");
		return result;
	}

	LogInformation("readNdefMessage : virtualTagHandle=%d, hMessage=%d", virtualTagHandle, hMessage);

	/*
	 * read Ndef Message
	 */
	uint32_t nMessageLength;
	uint32_t nActualMessageLength;
	uint8_t* pMessage;
	W_HANDLE hNextMessage;
	uint32_t offset;
	uint8_t* writePoint = (uint8_t *) malloc(MAXIMUM_READ_NDEF_BUFFER_SIZE);
	if (writePoint == null)
		{
		LogError("malloc writePoint is null");
		return result;
		}
	offset = 0;
	uint8_t* startPoint = writePoint;
	while (1)
	{
		nMessageLength = WNDEFGetMessageLength(hMessage);
		pMessage = (uint8_t *) malloc(nMessageLength);
		LogInformation("readNdefMessage : nMessageLength=%d", nMessageLength);
		if (pMessage == null)
		{
			LogError("pMessage is null");
			break;
		}
		if (WNDEFGetMessageContent(hMessage, pMessage, nMessageLength, &nActualMessageLength) != W_SUCCESS)
		{
			free(pMessage);
			LogError("WNDEFGetMessageContent fails");
			break;
		}
		offset += nMessageLength;
		if (offset >= MAXIMUM_READ_NDEF_BUFFER_SIZE)
		{
			free(pMessage);
			offset -= nMessageLength;
			LogError("Out of max buffer size");
			break;
		}
		memcpy(writePoint, pMessage, nMessageLength);
		writePoint += nMessageLength;
		free(pMessage);
		hNextMessage = WNDEFGetNextMessage(hMessage);
		WBasicCloseHandle(hMessage);
		hMessage = hNextMessage;
		if (W_NULL_HANDLE == hNextMessage)
		{
			LogInformation("readNdefMessage : Tchao");
			break;
		}
	} // Fin while

	result = env->NewByteArray(e, offset);
	if (result != NULL)
	{
		env->SetByteArrayRegion(e, result, 0, offset, (jbyte *) startPoint);
	}
	free(startPoint);
	LogInformation("read NdefMessage OK with length = %d", offset);

	return result;
}
Example #30
0
/* Loads the RD */
void ModuleMgrInit(MCoreBootDescriptor *BootDescriptor)
{
	/* Get pointers */
	MCoreRamDiskHeader_t *RdHeader = (MCoreRamDiskHeader_t*)BootDescriptor->RamDiskAddress;

	/* Sanity */
	if (BootDescriptor->RamDiskAddress == 0
		|| BootDescriptor->RamDiskSize == 0)
		return;

	/* Info */
	LogInformation("MDMG", "Initializing");

	/* Parse Kernel Exports */
	PeLoadKernelExports(BootDescriptor->KernelAddress, BootDescriptor->ExportsAddress);

	/* Validate Members */
	if (RdHeader->Magic != RAMDISK_MAGIC)
	{
		/* Error! */
		LogFatal("MDMG", "Invalid Magic in Ramdisk - 0x%x", RdHeader->Magic);
		return;
	}

	/* Valid Version? */
	if (RdHeader->Version != RAMDISK_VERSION_1)
	{
		/* Error! */
		LogFatal("MDMG", "Invalid RamDisk Version - 0x%x", RdHeader->Version);
		return;
	}

	/* Allocate list */
	GlbModMgrModules = list_create(LIST_NORMAL);

	/* Save Module-Count */
	uint32_t FileCount = RdHeader->FileCount;
	Addr_t RdPtr = BootDescriptor->RamDiskAddress + sizeof(MCoreRamDiskHeader_t);

	/* Point to first entry */
	MCoreRamDiskFileHeader_t *FilePtr = (MCoreRamDiskFileHeader_t*)RdPtr;

	/* Iterate */
	while (FileCount != 0)
	{
		/* We only care about modules */
		if (FilePtr->Type == RAMDISK_MODULE)
		{
			/* Get a pointer to the module header */
			MCoreRamDiskModuleHeader_t *ModuleHeader = 
				(MCoreRamDiskModuleHeader_t*)(BootDescriptor->RamDiskAddress + FilePtr->DataOffset);

			/* Allocate a new module */
			MCoreModule_t *Module = (MCoreModule_t*)kmalloc(sizeof(MCoreModule_t));

			/* Set */
			Module->Name = MStringCreate(ModuleHeader->ModuleName, StrUTF8);
			Module->Header = ModuleHeader;
			Module->Descriptor = NULL;

			/* Add to list */
			list_append(GlbModMgrModules, list_create_node(0, Module));
		}

		/* Next! */
		FilePtr++;
		FileCount--;
	}

	/* Info */
	LogInformation("MDMG", "Found %i Modules", GlbModMgrModules->length);

	/* Done! */
	GlbModMgrInitialized = 1;
}