-
Notifications
You must be signed in to change notification settings - Fork 142
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
ocall: add an example to show how to use OCALLs #64
Conversation
97db368
to
3e026f9
Compare
There was a problem hiding this 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.
ocall/ta/ocall_ta.c
Outdated
TEE_Param __unused params[TEE_NUM_PARAMS]) | ||
{ | ||
TEE_Result res; | ||
uint32_t eorig; |
There was a problem hiding this comment.
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
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, |
There was a problem hiding this comment.
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?)
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( |
There was a problem hiding this comment.
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).
ocall/host/main.c
Outdated
printf("\tNo buffer\n"); | ||
return TEEC_ERROR_BAD_PARAMETERS; | ||
} | ||
printf("\tBuffer size: %zu\n", params[0].tmpref.size); |
There was a problem hiding this comment.
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;
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; |
There was a problem hiding this comment.
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
ocall/host/main.c
Outdated
.u.ocall = &ocall_setting } | ||
}; | ||
res = TEEC_OpenSessionEx(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL, | ||
NULL, &err_origin, settings, 1); |
There was a problem hiding this comment.
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.
ocall/host/main.c
Outdated
switch (commandId) | ||
{ | ||
case TA_OCALL_CA_CMD_TEST_1: | ||
printf("\tOK\n"); |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
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, |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
We may want to trim down this example a bit and add stuff to the regression tests instead. |
8ea8897
to
e14157e
Compare
f216caf
to
ea4362e
Compare
There was a problem hiding this 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]>
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]>
ea4362e
to
ae6247e
Compare
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. |
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
andOUTPUT
parameters.Associated PR's: OP-TEE, OP-TEE Client, Linux.
Signed-off-by: Hernan Gatta [email protected]