Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Conversation

HernanGatta
Copy link

@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 [email protected]

Copy link
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.

TEE_Param __unused params[TEE_NUM_PARAMS])
{
TEE_Result res;
uint32_t eorig;
Copy link
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

if (param_types != expected_pt)
return TEE_ERROR_BAD_PARAMETERS;

res = TEE_InvokeCACommand(TEE_TIMEOUT_INFINITE, TA_OCALL_CA_CMD_TEST_1,
Copy link
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?)

if (param_types != expected_pt)
return TEE_ERROR_BAD_PARAMETERS;

const uint32_t ocall_param_types = TEE_PARAM_TYPES(
Copy link
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).

printf("\tNo buffer\n");
return TEEC_ERROR_BAD_PARAMETERS;
}
printf("\tBuffer size: %zu\n", params[0].tmpref.size);
Copy link
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;

}
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
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

.u.ocall = &ocall_setting }
};
res = TEEC_OpenSessionEx(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL,
NULL, &err_origin, settings, 1);
Copy link
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.

switch (commandId)
{
case TA_OCALL_CA_CMD_TEST_1:
printf("\tOK\n");
Copy link
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.

#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
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.

printf("\tOK\n");
break;
case TA_OCALL_CA_CMD_TEST_2:
printf("\tInput values: %u, %u\n", params[0].value.a,
Copy link
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.

printf("\tOK\n");
break;
case TA_OCALL_CA_CMD_TEST_3:
printf("\tInput string: %s\n", (char *)params[0].tmpref.buffer);
Copy link
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
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
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 <[email protected]>

ocall/host/main.c Outdated Show resolved Hide resolved
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 <[email protected]>
Acked-by: Jerome Forissier <[email protected]>
@github-actions
Copy link

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