Skip to content

ocall: add an example to show how to use OCALLs#64

Closed
HernanGatta wants to merge 1 commit intolinaro-swg:masterfrom
HernanGatta:optee-generic-rpc-support
Closed

ocall: add an example to show how to use OCALLs#64
HernanGatta wants to merge 1 commit intolinaro-swg:masterfrom
HernanGatta:optee-generic-rpc-support

Conversation

@HernanGatta
Copy link
Copy Markdown

@HernanGatta HernanGatta commented Sep 23, 2019

This example shows how to use OCALLs to allow TA's to call back into their host. This example includes handling OCALL requests and responding to them by modifying INOUT and OUTPUT parameters.

Associated PR's: OP-TEE, OP-TEE Client, Linux.

Signed-off-by: Hernan Gatta hegatta@microsoft.com

Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to move all printf info some DEBUG stderr path.

Comment thread ocall/ta/ocall_ta.c Outdated
TEE_Param __unused params[TEE_NUM_PARAMS])
{
TEE_Result res;
uint32_t eorig;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize to something meaningful and remove below empty line

Comment thread ocall/ta/ocall_ta.c Outdated
if (param_types != expected_pt)
return TEE_ERROR_BAD_PARAMETERS;

res = TEE_InvokeCACommand(TEE_TIMEOUT_INFINITE, TA_OCALL_CA_CMD_TEST_1,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: maybe prefer indent to (. (@jforissier, do we try to be strict on that?)

Comment thread ocall/ta/ocall_ta.c Outdated
if (param_types != expected_pt)
return TEE_ERROR_BAD_PARAMETERS;

const uint32_t ocall_param_types = TEE_PARAM_TYPES(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define all local variables at block entry (here function entry).

Comment thread ocall/host/main.c Outdated
printf("\tNo buffer\n");
return TEEC_ERROR_BAD_PARAMETERS;
}
printf("\tBuffer size: %zu\n", params[0].tmpref.size);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fail if params[0].tmpref.size < strlen(msg) + 1;

Comment thread ocall/host/main.c Outdated
}
printf("\tInput string: %s\n", (char *)params[0].tmpref.buffer);
printf("\tInput size: %zu\n", params[0].tmpref.size);
params[0].tmpref.size = strlen(msg) + 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto on params[0].tmpref.size < strlen(msg) + 1

Comment thread ocall/host/main.c Outdated
.u.ocall = &ocall_setting }
};
res = TEEC_OpenSessionEx(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL,
NULL, &err_origin, settings, 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: prefer

	TEEC_SessionSettingOcall ocall_setting = {
		.handler = ocall_handler,
		.context = &sess,
	};
	TEEC_SessionSetting settings = {
		.type = TEEC_SESSION_SETTING_OCALL,
		.u.ocall = &ocall_setting,
	};

	res = TEEC_OpenSessionEx(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL,
				 NULL, &err_origin, &settings, 1);

Same comment for run_test_no_ecall_params() at line 139.

Comment thread ocall/host/main.c Outdated
switch (commandId)
{
case TA_OCALL_CA_CMD_TEST_1:
printf("\tOK\n");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check here paramType == all NONE as expected by the API.

Comment thread ocall/ta/include/ocall_ta.h Outdated
#define TA_OCALL_CA_CMD_TEST_6 TA_OCALL_CMD_TEST_6
#define TA_OCALL_CA_CMD_TEST_7 TA_OCALL_CMD_TEST_7
#define TA_OCALL_CA_CMD_TEST_8 TA_OCALL_CMD_TEST_8
#define TA_OCALL_CA_CMD_TEST_9 TA_OCALL_CMD_TEST_9
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State somewhere what each test do.

Comment thread ocall/host/main.c Outdated
printf("\tOK\n");
break;
case TA_OCALL_CA_CMD_TEST_2:
printf("\tInput values: %u, %u\n", params[0].value.a,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check here paramType is VALUE_IN | NONE | NONE | NONE.

Comment thread ocall/host/main.c Outdated
printf("\tOK\n");
break;
case TA_OCALL_CA_CMD_TEST_3:
printf("\tInput string: %s\n", (char *)params[0].tmpref.buffer);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check paramType...

and same for the cases below.

@jenswi-linaro
Copy link
Copy Markdown
Contributor

We may want to trim down this example a bit and add stuff to the regression tests instead.
But that can wait until we're done with the other parts.

@HernanGatta HernanGatta force-pushed the optee-generic-rpc-support branch 3 times, most recently from 8ea8897 to e14157e Compare April 16, 2020 03:19
@HernanGatta HernanGatta changed the title OCALL example ocall: add an example to show how to use OCALLs Jun 10, 2020
@HernanGatta HernanGatta force-pushed the optee-generic-rpc-support branch 2 times, most recently from f216caf to ea4362e Compare October 19, 2020 06:20
Copy link
Copy Markdown
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One spelling mistake below (we changed the type in the client library). Other than that, LGTM, it is a nice example.

Acked-by: Jerome Forissier <jerome@forissier.org>

Comment thread ocall/host/main.c Outdated
The example first initializes a TEE context using the new settings API. It
then opens a session against the example OCALL TA via the new API to
configure sessions. The TA issues an OCALL during session open, which is
handled by the host. Thereafter, it performs a function invocation into the
OCALL TA to request that the latter call it back.

The OCALLs include value and memref parameters that are passed in multiple
directions. Via these parameters the TA and CA exchange information the
same way they would during a normal CA-to-TA function invocation.

Signed-off-by: Hernan Gatta <hegatta@microsoft.com>
Acked-by: Jerome Forissier <jerome@forissier.org>
@github-actions
Copy link
Copy Markdown

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions Bot added the Stale label Dec 24, 2021
@github-actions github-actions Bot closed this Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants