Ejemplo n.º 1
0
int main()
{
	TEEC_Context context;
	TEEC_Result ret;
	TEEC_SharedMemory shared_mem;

	printf("Starting\n");

	ret = TEEC_InitializeContext(NULL, &context);
	if (ret != TEEC_SUCCESS)
		printf("Error Connecting to the daemon: 0x%x\n", ret);

	shared_mem.size = 1024;
	shared_mem.flags = TEEC_MEM_INPUT | TEEC_MEM_INPUT;

	ret = TEEC_AllocateSharedMemory(&context, &shared_mem);
	if (ret != TEEC_SUCCESS) {
		printf("Error allocating memory: 0x%x\n", ret);
		printf("Error is %s: %d\n", strerror(errno), errno);
	}

	printf("Session entering while loop\n");
	(void)fflush(stdout);
	TEEC_ReleaseSharedMemory(&shared_mem);

	while (1) {
	}
	return 0;
}
Ejemplo n.º 2
0
static TEEC_Result do_counter_tests(TEEC_Session *session, TEEC_Context *context)
{
	TEEC_Result ret;
	uint64_t previous_value;
	TEEC_SharedMemory inout_mem = {0};
	uint64_t value;

	inout_mem.buffer = &value;
	inout_mem.size = sizeof(value);
	inout_mem.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;

	ret = TEEC_RegisterSharedMemory(context, &inout_mem);
	if (ret != TEE_SUCCESS) {
		printf("Failed to register shared memory");
		goto end;
	}

	/* Get and increment the counter for the first time */
	ret = invoke_command(session, &inout_mem, CMD_GET_CTR);
	if (ret != TEEC_SUCCESS)
		goto end;

	previous_value = value;
	printf("Value after the first get_counter: %d\n", (int)value);

	/* Increment it again and check that the value has changed */
	ret = invoke_command(session, &inout_mem, CMD_GET_CTR);
	if (ret != TEEC_SUCCESS)
		goto end;

	printf("Value after the second get_counter: %d\n", (int)value);
	if (++previous_value != value)
		ret = TEEC_ERROR_GENERIC;

end:
	TEEC_ReleaseSharedMemory(&inout_mem);
	return ret;
}
Ejemplo n.º 3
0
int main()
{
	TEEC_Context context;
	TEEC_Session session;
	TEEC_Operation operation;
	TEEC_SharedMemory in_mem;
	TEEC_SharedMemory out_mem;
	TEEC_Result ret;
	uint32_t return_origin;
	uint32_t connection_method = TEEC_LOGIN_PUBLIC;
	char data[DATA_SIZE];
	uint8_t sha1[SHA1_SIZE];
	int i;

	printf("START: example SHA1 calc app\n");

	memset((void *)&in_mem, 0, sizeof(in_mem));
	memset((void *)&out_mem, 0, sizeof(out_mem));
	memset((void *)&operation, 0, sizeof(operation));
	memset(data, 'y', DATA_SIZE);
	memset(sha1, 0, SHA1_SIZE);

	/* Initialize context */
	printf("Initializing context: ");
	ret = TEEC_InitializeContext(NULL, &context);
	if (ret != TEEC_SUCCESS) {
		printf("TEEC_InitializeContext failed: 0x%x\n", ret);
		goto end_1;
	} else {
		printf("initiliazed\n");
	}

	/* Open session is expecting HASH algorithm */
	operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
	operation.params[0].value.a = HASH_SHA1;

	/* Open session */
	printf("Openning session: ");
	ret = TEEC_OpenSession(&context, &session, &uuid, connection_method,
			       NULL, &operation, &return_origin);
	if (ret != TEEC_SUCCESS) {
		printf("TEEC_OpenSession failed: 0x%x\n", ret);
		goto end_2;
	} else {
		printf("opened\n");
	}

	/* Register shared memory for initial hash */

	/* Data */
	in_mem.buffer = data;
	in_mem.size = DATA_SIZE;
	in_mem.flags = TEEC_MEM_INPUT;

	ret = TEEC_RegisterSharedMemory(&context, &in_mem);
	if (ret != TEE_SUCCESS) {
		printf("Failed to register DATA shared memory\n");
		goto end_3;
	}
	printf("Registered in mem..\n");

	/* Fill operation parameters */
	operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
	operation.params[0].memref.parent = &in_mem;

	/* Invoke command */
	printf("Invoking command: Update sha1: ");
	ret = TEEC_InvokeCommand(&session, HASH_UPDATE, &operation, &return_origin);
	if (ret != TEEC_SUCCESS) {
		printf("TEEC_InvokeCommand failed: 0x%x\n", ret);
		goto end_3;
	} else {
		printf("done\n");
	}

	/* register a shared memory region to hold the output of the sha1 operation */
	out_mem.buffer = sha1;
	out_mem.size = SHA1_SIZE;
	out_mem.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;

	ret = TEEC_RegisterSharedMemory(&context, &out_mem);
	if (ret != TEE_SUCCESS) {
		printf("Failed to allocate SHA1 shared memory\n");
		goto end_3;
	}
	printf("Registered out mem..\n");

	/*
	 * Send some more data to calculate the hash over, this will be added to the origional hash
	 * .  This is not strictly needed it is a test for passing 2 memref params in a single
	 * operation
	 */
	memset(data, 'Z', DATA_SIZE);

	/* Fill operation parameters */
	operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_MEMREF_WHOLE,
						TEEC_NONE, TEEC_NONE);
	/*
	 * reuse the origional input shared memory, because we have just updated the contents
	 * of the buffer
	 */
	operation.params[0].memref.parent = &in_mem;
	operation.params[1].memref.parent = &out_mem;

	/* Invoke command */
	printf("Invoking command: Do final sha1: ");
	ret = TEEC_InvokeCommand(&session, HASH_DO_FINAL, &operation, &return_origin);
	if (ret != TEEC_SUCCESS) {
		printf("TEEC_InvokeCommand failed: 0x%x\n", ret);
		goto end_4;
	} else {
		printf("done\n");
	}

	/* Printf sha1 buf */
	printf("Calculated sha1: ");
	for (i = 0; i < SHA1_SIZE; i++)
		printf("%02x", sha1[i]);
	printf("\n");

	/* Cleanup used connection/resources */

end_4:

	printf("Releasing shared out memory..\n");
	TEEC_ReleaseSharedMemory(&out_mem);

end_3:
	printf("Releasing shared in memory..\n");
	TEEC_ReleaseSharedMemory(&in_mem);
	printf("Closing session..\n");
	TEEC_CloseSession(&session);

end_2:

	printf("Finalizing ctx..\n");
	TEEC_FinalizeContext(&context);
end_1:

	printf("END: example SHA1 calc app\n");
	exit(ret);
}
Ejemplo n.º 4
0
static void free_shm()
{
	TEEC_ReleaseSharedMemory(&in_shm);
	TEEC_ReleaseSharedMemory(&out_shm);
}
int verify_start_modem(void *access_mem_start,
                       size_t shared_mem_size,
                       size_t access_private_mem_size,
                       struct access_image_descr *access_image_descr)
{
    int ret = 0;

    TEEC_Result teec_ret = TEEC_ERROR_GENERIC;
    TEEC_Context ctx;
    TEEC_SharedMemory shm;
    TEEC_ErrorOrigin org;
    TEEC_Session session;
    TEEC_Operation operation;
    TEEC_UUID ta_static_uuid = STATIC_TA_UUID;

    (void)access_mem_start;
    (void)shared_mem_size;
    (void)access_private_mem_size;

    if (NULL == access_image_descr ||
            NULL == access_image_descr->elf_hdr) {
        ret = -1;
        dprintf(ERROR, "NULL pointer error");
        goto out;
    }

    teec_ret = TEEC_InitializeContext(NULL, &ctx);

    if (teec_ret != TEEC_SUCCESS) {
        goto out;
    }

    teec_ret = TEEC_OpenSession(&ctx, &session, &ta_static_uuid,
                                TEEC_LOGIN_PUBLIC, NULL, NULL, &org);

    if (teec_ret != TEEC_SUCCESS) {
        goto out_finalize;
    }

    shm.size = 4;
    shm.flags = TEEC_MEM_INPUT;
    teec_ret = TEEC_AllocateSharedMemory(&ctx, &shm);

    if (teec_ret != TEEC_SUCCESS) {
        goto out_close;
    }

    operation.memRefs[0] = shm;
    operation.flags = TEEC_MEMREF_0_USED;

    /* Point to entry. */
    *((unsigned int *)shm.buffer) =
        (uintptr_t)((uint8_t *) access_image_descr->elf_hdr +
                       ELF_ENTRY_OFFSET);

    teec_ret = TEEC_InvokeCommand(&session, BASS_APP_VERITY_START_MODEM,
                                  &operation, &org);

    if (teec_ret != TEEC_SUCCESS) {
        goto out_release;
    }

out_release:
    TEEC_ReleaseSharedMemory(&shm);

out_close:
    TEEC_CloseSession(&session);

out_finalize:
    TEEC_FinalizeContext(&ctx);

out:

    if (teec_ret != TEEC_SUCCESS) {
        ret = -1;
    }

    return ret;
}